All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent eafd18dac0
commit 25c3ba7338
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -48,12 +48,13 @@ DownloadManager* DownloadManager::self = nullptr;
DownloadManager* DownloadManager::getInstance()
{
if (!self)
if (!self) {
self = new DownloadManager(Gui::getMainWindow());
}
return self;
}
DownloadManager::DownloadManager(QWidget *parent)
DownloadManager::DownloadManager(QWidget* parent)
: QDialog(parent)
, m_autoSaver(new AutoSaver(this))
, m_manager(new NetworkAccessManager(this))
@@ -73,11 +74,12 @@ DownloadManager::DownloadManager(QWidget *parent)
load();
Gui::DockWindowManager* pDockMgr = Gui::DockWindowManager::instance();
QDockWidget* dw = pDockMgr->addDockWindow(QT_TR_NOOP("Download Manager"),
this, Qt::BottomDockWidgetArea);
dw->setFeatures(QDockWidget::DockWidgetMovable|
QDockWidget::DockWidgetFloatable|
QDockWidget::DockWidgetClosable);
QDockWidget* dw
= pDockMgr->addDockWindow(QT_TR_NOOP("Download Manager"), this, Qt::BottomDockWidgetArea);
dw->setFeatures(
QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable
| QDockWidget::DockWidgetClosable
);
dw->setAttribute(Qt::WA_DeleteOnClose);
dw->show();
}
@@ -86,8 +88,9 @@ DownloadManager::~DownloadManager()
{
m_autoSaver->changeOccurred();
m_autoSaver->saveIfNecessary();
if (m_iconProvider)
if (m_iconProvider) {
delete m_iconProvider;
}
delete ui;
self = nullptr;
}
@@ -101,8 +104,9 @@ int DownloadManager::activeDownloads() const
{
int count = 0;
for (int i = 0; i < m_downloads.count(); ++i) {
if (m_downloads.at(i)->stopButton->isEnabled())
if (m_downloads.at(i)->stopButton->isEnabled()) {
++count;
}
}
return count;
}
@@ -112,8 +116,8 @@ QUrl DownloadManager::redirectUrl(const QUrl& url) const
QUrl redirectUrl = url;
if (url.host() == QLatin1String("www.dropbox.com")) {
QUrlQuery urlQuery(url);
QList< QPair<QString, QString> > query = urlQuery.queryItems();
for (const auto & it : query) {
QList<QPair<QString, QString>> query = urlQuery.queryItems();
for (const auto& it : query) {
if (it.first == QLatin1String("dl")) {
if (it.second == QLatin1String("0\r\n")) {
urlQuery.removeQueryItem(QLatin1String("dl"));
@@ -141,30 +145,33 @@ QUrl DownloadManager::redirectUrl(const QUrl& url) const
return redirectUrl;
}
void DownloadManager::download(const QNetworkRequest &request, bool requestFileName)
void DownloadManager::download(const QNetworkRequest& request, bool requestFileName)
{
if (request.url().isEmpty())
if (request.url().isEmpty()) {
return;
}
std::cout << request.url().toString().toStdString() << std::endl;
handleUnsupportedContent(m_manager->get(request), requestFileName);
}
void DownloadManager::handleUnsupportedContent(QNetworkReply *reply, bool requestFileName)
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, bool requestFileName)
{
if (!reply || reply->url().isEmpty())
if (!reply || reply->url().isEmpty()) {
return;
}
QVariant header = reply->header(QNetworkRequest::ContentLengthHeader);
bool ok;
int size = header.toInt(&ok);
if (ok && size == 0)
if (ok && size == 0) {
return;
}
auto item = new DownloadItem(reply, requestFileName, this);
addItem(item);
}
void DownloadManager::addItem(DownloadItem *item)
void DownloadManager::addItem(DownloadItem* item)
{
connect(item, &DownloadItem::statusChanged, this, &DownloadManager::updateRow);
int row = m_downloads.count();
@@ -183,23 +190,26 @@ void DownloadManager::updateRow()
{
auto item = qobject_cast<DownloadItem*>(sender());
int row = m_downloads.indexOf(item);
if (-1 == row)
if (-1 == row) {
return;
if (!m_iconProvider)
}
if (!m_iconProvider) {
m_iconProvider = new QFileIconProvider();
}
QIcon icon = m_iconProvider->icon(QFileInfo(item->m_output.fileName()));
if (icon.isNull())
if (icon.isNull()) {
icon = style()->standardIcon(QStyle::SP_FileIcon);
}
item->fileIcon->setPixmap(icon.pixmap(48, 48));
ui->downloadsView->setRowHeight(row, item->minimumSizeHint().height());
bool remove = false;
if (item->downloadedSuccessfully()
&& removePolicy() == DownloadManager::SuccessFullDownload) {
if (item->downloadedSuccessfully() && removePolicy() == DownloadManager::SuccessFullDownload) {
remove = true;
}
if (remove)
if (remove) {
m_model->removeRow(row);
}
ui->cleanupButton->setEnabled(m_downloads.count() - activeDownloads() > 0);
}
@@ -211,8 +221,9 @@ DownloadManager::RemovePolicy DownloadManager::removePolicy() const
void DownloadManager::setRemovePolicy(RemovePolicy policy)
{
if (policy == m_removePolicy)
if (policy == m_removePolicy) {
return;
}
m_removePolicy = policy;
m_autoSaver->changeOccurred();
}
@@ -221,16 +232,25 @@ void DownloadManager::save() const
{
QSettings settings;
settings.beginGroup(QLatin1String("downloadmanager"));
QMetaEnum removePolicyEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("RemovePolicy"));
settings.setValue(QLatin1String("removeDownloadsPolicy"), QLatin1String(removePolicyEnum.valueToKey(m_removePolicy)));
QMetaEnum removePolicyEnum = staticMetaObject.enumerator(
staticMetaObject.indexOfEnumerator("RemovePolicy")
);
settings.setValue(
QLatin1String("removeDownloadsPolicy"),
QLatin1String(removePolicyEnum.valueToKey(m_removePolicy))
);
settings.setValue(QLatin1String("size"), size());
if (m_removePolicy == Exit)
if (m_removePolicy == Exit) {
return;
}
for (int i = 0; i < m_downloads.count(); ++i) {
QString key = QString(QLatin1String("download_%1_")).arg(i);
settings.setValue(key + QLatin1String("url"), m_downloads[i]->m_url);
settings.setValue(key + QLatin1String("location"), QFileInfo(m_downloads[i]->m_output).filePath());
settings.setValue(
key + QLatin1String("location"),
QFileInfo(m_downloads[i]->m_output).filePath()
);
settings.setValue(key + QLatin1String("done"), m_downloads[i]->downloadedSuccessfully());
}
int i = m_downloads.count();
@@ -248,13 +268,17 @@ void DownloadManager::load()
QSettings settings;
settings.beginGroup(QLatin1String("downloadmanager"));
QSize size = settings.value(QLatin1String("size")).toSize();
if (size.isValid())
if (size.isValid()) {
resize(size);
QByteArray value = settings.value(QLatin1String("removeDownloadsPolicy"), QLatin1String("Never")).toByteArray();
QMetaEnum removePolicyEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("RemovePolicy"));
m_removePolicy = removePolicyEnum.keyToValue(value) == -1 ?
Never :
static_cast<RemovePolicy>(removePolicyEnum.keyToValue(value));
}
QByteArray value
= settings.value(QLatin1String("removeDownloadsPolicy"), QLatin1String("Never")).toByteArray();
QMetaEnum removePolicyEnum = staticMetaObject.enumerator(
staticMetaObject.indexOfEnumerator("RemovePolicy")
);
m_removePolicy = removePolicyEnum.keyToValue(value) == -1
? Never
: static_cast<RemovePolicy>(removePolicyEnum.keyToValue(value));
int i = 0;
QString key = QString(QLatin1String("download_%1_")).arg(i);
@@ -281,8 +305,9 @@ void DownloadManager::load()
void DownloadManager::cleanup()
{
if (m_downloads.isEmpty())
if (m_downloads.isEmpty()) {
return;
}
m_model->removeRows(0, m_downloads.count());
updateItemCount();
if (m_downloads.isEmpty() && m_iconProvider) {
@@ -300,31 +325,34 @@ void DownloadManager::updateItemCount()
// ----------------------------------------------------------------------------
DownloadModel::DownloadModel(DownloadManager *downloadManager, QObject *parent)
DownloadModel::DownloadModel(DownloadManager* downloadManager, QObject* parent)
: QAbstractListModel(parent)
, m_downloadManager(downloadManager)
{
}
{}
QVariant DownloadModel::data(const QModelIndex &index, int role) const
QVariant DownloadModel::data(const QModelIndex& index, int role) const
{
if (index.row() < 0 || index.row() >= rowCount(index.parent()))
if (index.row() < 0 || index.row() >= rowCount(index.parent())) {
return {};
if (role == Qt::ToolTipRole)
if (!m_downloadManager->m_downloads.at(index.row())->downloadedSuccessfully())
}
if (role == Qt::ToolTipRole) {
if (!m_downloadManager->m_downloads.at(index.row())->downloadedSuccessfully()) {
return m_downloadManager->m_downloads.at(index.row())->downloadInfoLabel->text();
}
}
return {};
}
int DownloadModel::rowCount(const QModelIndex &parent) const
int DownloadModel::rowCount(const QModelIndex& parent) const
{
return (parent.isValid()) ? 0 : m_downloadManager->m_downloads.count();
}
bool DownloadModel::removeRows(int row, int count, const QModelIndex &parent)
bool DownloadModel::removeRows(int row, int count, const QModelIndex& parent)
{
if (parent.isValid())
if (parent.isValid()) {
return false;
}
int lastRow = row + count - 1;
for (int i = lastRow; i >= row; --i) {