Browse Source

Merge pull request #9268 from Chocobo1/clean

Put temporary files in qbt own temp folder and cleanups
adaptive-webui-19844
Mike Tzou 6 years ago committed by GitHub
parent
commit
89081d5365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      qbittorrent.pro
  2. 2
      src/base/bittorrent/session.cpp
  3. 4
      src/base/iconprovider.cpp
  4. 5
      src/base/iconprovider.h
  5. 25
      src/gui/guiiconprovider.cpp
  6. 10
      src/gui/guiiconprovider.h
  7. 3
      src/src.pro

4
qbittorrent.pro

@ -17,6 +17,10 @@ tarball.commands += rm -fR $${PROJECT_NAME}-$${PROJECT_VERSION}
QMAKE_EXTRA_TARGETS += tarball QMAKE_EXTRA_TARGETS += tarball
# Translations included here (at top level) is to avoid regenerating the .qm files
# every time when src.pro is processed
include(src/lang/lang.pri)
# For Qt Creator beautifier # For Qt Creator beautifier
DISTFILES += \ DISTFILES += \
uncrustify.cfg uncrustify.cfg

2
src/base/bittorrent/session.cpp

@ -2300,7 +2300,7 @@ bool Session::loadMetadata(const MagnetUri &magnetUri)
p.max_connections = maxConnectionsPerTorrent(); p.max_connections = maxConnectionsPerTorrent();
p.max_uploads = maxUploadsPerTorrent(); p.max_uploads = maxUploadsPerTorrent();
QString savePath = QString("%1/%2").arg(QDir::tempPath(), hash); QString savePath = QString("%1/%2").arg(Utils::Fs::tempPath(), hash);
p.save_path = Utils::Fs::toNativePath(savePath).toStdString(); p.save_path = Utils::Fs::toNativePath(savePath).toStdString();
// Forced start // Forced start

4
src/base/iconprovider.cpp

@ -29,8 +29,6 @@
#include "iconprovider.h" #include "iconprovider.h"
#include <QString>
IconProvider::IconProvider(QObject *parent) IconProvider::IconProvider(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
@ -57,7 +55,7 @@ IconProvider *IconProvider::instance()
return m_instance; return m_instance;
} }
QString IconProvider::getIconPath(const QString &iconId) QString IconProvider::getIconPath(const QString &iconId) const
{ {
return ":/icons/qbt-theme/" + iconId + ".png"; return ":/icons/qbt-theme/" + iconId + ".png";
} }

5
src/base/iconprovider.h

@ -31,8 +31,7 @@
#define ICONPROVIDER_H #define ICONPROVIDER_H
#include <QObject> #include <QObject>
#include <QString>
class QString;
class IconProvider : public QObject class IconProvider : public QObject
{ {
@ -43,7 +42,7 @@ public:
static void freeInstance(); static void freeInstance();
static IconProvider *instance(); static IconProvider *instance();
virtual QString getIconPath(const QString &iconId); virtual QString getIconPath(const QString &iconId) const;
protected: protected:
explicit IconProvider(QObject *parent = nullptr); explicit IconProvider(QObject *parent = nullptr);

25
src/gui/guiiconprovider.cpp

@ -30,12 +30,14 @@
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include <QIcon> #include <QIcon>
#include <QVector>
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#endif #endif
#include "base/preferences.h" #include "base/preferences.h"
#include "base/utils/fs.h"
GuiIconProvider::GuiIconProvider(QObject *parent) GuiIconProvider::GuiIconProvider(QObject *parent)
: IconProvider(parent) : IconProvider(parent)
@ -57,12 +59,12 @@ GuiIconProvider *GuiIconProvider::instance()
return static_cast<GuiIconProvider *>(m_instance); return static_cast<GuiIconProvider *>(m_instance);
} }
QIcon GuiIconProvider::getIcon(const QString &iconId) QIcon GuiIconProvider::getIcon(const QString &iconId) const
{ {
return getIcon(iconId, iconId); return getIcon(iconId, iconId);
} }
QIcon GuiIconProvider::getIcon(const QString &iconId, const QString &fallback) QIcon GuiIconProvider::getIcon(const QString &iconId, const QString &fallback) const
{ {
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
if (m_useSystemTheme) { if (m_useSystemTheme) {
@ -78,7 +80,7 @@ QIcon GuiIconProvider::getIcon(const QString &iconId, const QString &fallback)
return QIcon(IconProvider::getIconPath(iconId)); return QIcon(IconProvider::getIconPath(iconId));
} }
QIcon GuiIconProvider::getFlagIcon(const QString &countryIsoCode) QIcon GuiIconProvider::getFlagIcon(const QString &countryIsoCode) const
{ {
if (countryIsoCode.isEmpty()) return QIcon(); if (countryIsoCode.isEmpty()) return QIcon();
return QIcon(":/icons/flags/" + countryIsoCode.toLower() + ".svg"); return QIcon(":/icons/flags/" + countryIsoCode.toLower() + ".svg");
@ -89,7 +91,7 @@ QIcon GuiIconProvider::getFlagIcon(const QString &countryIsoCode)
// Otherwise, the UI looks broken if the icon is not available // Otherwise, the UI looks broken if the icon is not available
// in the correct size. // in the correct size.
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
QIcon GuiIconProvider::generateDifferentSizes(const QIcon &icon) QIcon GuiIconProvider::generateDifferentSizes(const QIcon &icon) const
{ {
// if icon is loaded from SVG format, it already contains all the required sizes and we shall not resize it // if icon is loaded from SVG format, it already contains all the required sizes and we shall not resize it
// In that case it will be available in the following sizes: // In that case it will be available in the following sizes:
@ -99,16 +101,15 @@ QIcon GuiIconProvider::generateDifferentSizes(const QIcon &icon)
return icon; return icon;
QIcon newIcon; QIcon newIcon;
QList<QSize> requiredSizes; const QVector<QSize> requiredSizes {{16, 16}, {24, 24}, {32, 32}};
requiredSizes << QSize(16, 16) << QSize(24, 24) << QSize(32, 32); const QVector<QIcon::Mode> modes {QIcon::Normal, QIcon::Active, QIcon::Selected, QIcon::Disabled};
QList<QIcon::Mode> modes; for (const QSize &size : requiredSizes) {
modes << QIcon::Normal << QIcon::Active << QIcon::Selected << QIcon::Disabled; for (const QIcon::Mode mode : modes) {
foreach (const QSize &size, requiredSizes) {
foreach (QIcon::Mode mode, modes) {
QPixmap pixoff = icon.pixmap(size, mode, QIcon::Off); QPixmap pixoff = icon.pixmap(size, mode, QIcon::Off);
if (pixoff.height() > size.height()) if (pixoff.height() > size.height())
pixoff = pixoff.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); pixoff = pixoff.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
newIcon.addPixmap(pixoff, mode, QIcon::Off); newIcon.addPixmap(pixoff, mode, QIcon::Off);
QPixmap pixon = icon.pixmap(size, mode, QIcon::On); QPixmap pixon = icon.pixmap(size, mode, QIcon::On);
if (pixon.height() > size.height()) if (pixon.height() > size.height())
pixon = pixoff.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); pixon = pixoff.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
@ -120,11 +121,11 @@ QIcon GuiIconProvider::generateDifferentSizes(const QIcon &icon)
} }
#endif #endif
QString GuiIconProvider::getIconPath(const QString &iconId) QString GuiIconProvider::getIconPath(const QString &iconId) const
{ {
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
if (m_useSystemTheme) { if (m_useSystemTheme) {
QString path = QDir::temp().absoluteFilePath(iconId + ".png"); QString path = Utils::Fs::tempPath() + iconId + ".png";
if (!QFile::exists(path)) { if (!QFile::exists(path)) {
const QIcon icon = QIcon::fromTheme(iconId); const QIcon icon = QIcon::fromTheme(iconId);
if (!icon.isNull()) if (!icon.isNull())

10
src/gui/guiiconprovider.h

@ -43,10 +43,10 @@ public:
static void initInstance(); static void initInstance();
static GuiIconProvider *instance(); static GuiIconProvider *instance();
QIcon getIcon(const QString &iconId); QIcon getIcon(const QString &iconId) const;
QIcon getIcon(const QString &iconId, const QString &fallback); QIcon getIcon(const QString &iconId, const QString &fallback) const;
QIcon getFlagIcon(const QString &countryIsoCode); QIcon getFlagIcon(const QString &countryIsoCode) const;
QString getIconPath(const QString &iconId); QString getIconPath(const QString &iconId) const override;
private slots: private slots:
void configure(); void configure();
@ -55,7 +55,7 @@ private:
explicit GuiIconProvider(QObject *parent = nullptr); explicit GuiIconProvider(QObject *parent = nullptr);
~GuiIconProvider(); ~GuiIconProvider();
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
QIcon generateDifferentSizes(const QIcon &icon); QIcon generateDifferentSizes(const QIcon &icon) const;
bool m_useSystemTheme; bool m_useSystemTheme;
#endif #endif

3
src/src.pro

@ -76,7 +76,4 @@ RESOURCES += \
lang/lang.qrc \ lang/lang.qrc \
searchengine/searchengine.qrc searchengine/searchengine.qrc
# Translations
include(lang/lang.pri)
DESTDIR = . DESTDIR = .

Loading…
Cancel
Save