Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appearance tab. Issue #6363. #6375

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
96 changes: 63 additions & 33 deletions src/base/preferences.cpp
Expand Up @@ -31,6 +31,7 @@
*/

#include <QCryptographicHash>
#include <QDebug>
#include <QDir>
#include <QLocale>
#include <QPair>
Expand All @@ -57,9 +58,11 @@
#include "logger.h"
#include "preferences.h"

Preferences* Preferences::m_instance = 0;
Preferences *Preferences::m_instance = 0;

Preferences::Preferences() {}
Preferences::Preferences()
{
}

Preferences *Preferences::instance()
{
Expand Down Expand Up @@ -90,17 +93,41 @@ void Preferences::setValue(const QString &key, const QVariant &value)
SettingsStorage::instance()->storeValue(key, value);
}

// General options
// Appearance/Language options
QString Preferences::getLocale() const
{
return value("Preferences/General/Locale", QLocale::system().name()).toString();
return value("Preferences/Appearance/Locale", QLocale::system().name()).toString();
}

void Preferences::setLocale(const QString &locale)
{
setValue("Preferences/General/Locale", locale);
setValue("Preferences/Appearance/Locale", locale);
}

#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
bool Preferences::useSystemIconTheme() const
{
return value("Preferences/Appearance/useSystemIconTheme", true).toBool();
}

void Preferences::setSystemIconTheme(bool enabled)
{
setValue("Preferences/Appearance/useSystemIconTheme", enabled);
}

#endif

bool Preferences::useAlternatingRowColors() const
{
return value("Preferences/Appearance/AlternatingRowColors", true).toBool();
}

void Preferences::setAlternatingRowColors(bool b)
{
setValue("Preferences/Appearance/AlternatingRowColors", b);
}

// General options
bool Preferences::deleteTorrentFilesAsDefault() const
{
return value("Preferences/General/DeleteTorrentsFilesAsDefault", false).toBool();
Expand Down Expand Up @@ -131,16 +158,6 @@ void Preferences::showSpeedInTitleBar(bool show)
setValue("Preferences/General/SpeedInTitleBar", show);
}

bool Preferences::useAlternatingRowColors() const
{
return value("Preferences/General/AlternatingRowColors", true).toBool();
}

void Preferences::setAlternatingRowColors(bool b)
{
setValue("Preferences/General/AlternatingRowColors", b);
}

bool Preferences::getHideZeroValues() const
{
return value("Preferences/General/HideZeroValues", false).toBool();
Expand Down Expand Up @@ -250,6 +267,7 @@ void Preferences::setWinStartup(bool b)
settings.remove("qBittorrent");
}
}

#endif

// Downloads
Expand Down Expand Up @@ -702,17 +720,6 @@ void Preferences::resolvePeerHostNames(bool resolve)
setValue("Preferences/Connection/ResolvePeerHostNames", resolve);
}

#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
bool Preferences::useSystemIconTheme() const
{
return value("Preferences/Advanced/useSystemIconTheme", true).toBool();
}

void Preferences::useSystemIconTheme(bool enabled)
{
setValue("Preferences/Advanced/useSystemIconTheme", enabled);
}
#endif

bool Preferences::recursiveDownloadDisabled() const
{
Expand All @@ -725,7 +732,8 @@ void Preferences::disableRecursiveDownload(bool disable)
}

#ifdef Q_OS_WIN
namespace {
namespace
{
enum REG_SEARCH_TYPE
{
USER,
Expand Down Expand Up @@ -814,7 +822,7 @@ namespace {
versions.sort();

bool found = false;
while(!found && !versions.empty()) {
while (!found && !versions.empty()) {
const QString version = versions.takeLast() + "\\InstallPath";
LPWSTR lpSubkey = new WCHAR[version.size() + 1];
version.toWCharArray(lpSubkey);
Expand Down Expand Up @@ -844,7 +852,6 @@ namespace {

return path;
}

}

QString Preferences::getPythonPath()
Expand Down Expand Up @@ -950,6 +957,7 @@ void Preferences::setMagnetLinkAssoc(bool set)

SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
}

#endif

#ifdef Q_OS_MAC
Expand Down Expand Up @@ -1006,6 +1014,7 @@ void Preferences::setMagnetLinkAssoc()
CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle());
LSSetDefaultHandlerForURLScheme(magnetUrlScheme, myBundleId);
}

#endif

int Preferences::getTrackerPort() const
Expand All @@ -1028,6 +1037,7 @@ void Preferences::setUpdateCheckEnabled(bool enabled)
{
setValue("Preferences/Advanced/updateCheck", enabled);
}

#endif

bool Preferences::confirmTorrentDeletion() const
Expand Down Expand Up @@ -1132,7 +1142,7 @@ void Preferences::setMainLastDir(const QString &path)
}

#ifndef DISABLE_GUI
QSize Preferences::getPrefSize(const QSize& defaultSize) const
QSize Preferences::getPrefSize(const QSize &defaultSize) const
{
return value("Preferences/State/size", defaultSize).toSize();
}
Expand All @@ -1141,6 +1151,7 @@ void Preferences::setPrefSize(const QSize &size)
{
setValue("Preferences/State/size", size);
}

#endif

QPoint Preferences::getPrefPos() const
Expand Down Expand Up @@ -1477,7 +1488,7 @@ void Preferences::setTransHeaderState(const QByteArray &state)
#endif
}

//From old RssSettings class
// From old RssSettings class
bool Preferences::isRSSEnabled() const
{
return value("Preferences/RSS/RSSEnabled", false).toBool();
Expand Down Expand Up @@ -1590,6 +1601,26 @@ void Preferences::setSpeedWidgetGraphEnable(int id, const bool enable)

void Preferences::upgrade()
{
// Migrate single-value prefs to new section/name
QList<QPair<QString, QString>> prefsToMigrate = {
{ "Preferences/General/Locale", "Preferences/Appearance/Locale" },
{ "Preferences/General/AlternatingRowColors", "Preferences/Appearance/AlternatingRowColors" },
{ "Preferences/Advanced/useSystemIconTheme", "Preferences/Appearance/useSystemIconTheme" },
};

for (auto iter = prefsToMigrate.begin(); iter != prefsToMigrate.end(); ++iter) {
QString pre(iter->first);
QString post(iter->second);

QVariant preValue = value(pre);

if (!preValue.isNull()) {
qDebug() << "Migrating preference" << pre << "->" << post;
setValue(post, pre);
SettingsStorage::instance()->removeValue(pre);
}
}

// Move RSS cookies to global storage
QList<QNetworkCookie> cookies = getNetworkCookies();
QVariantMap hostsTable = value("Rss/hosts_cookies").toMap();
Expand All @@ -1611,10 +1642,9 @@ void Preferences::upgrade()
QStringList labels = value("TransferListFilters/customLabels").toStringList();
if (!labels.isEmpty()) {
QVariantMap categories = value("BitTorrent/Session/Categories").toMap();
foreach (const QString &label, labels) {
foreach (const QString &label, labels)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (const QString &label: labels)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was from uncrustify.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I meant that one can use range-based for here too, instead of Qt's foreach macro

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - but my point is that this an automated change in the code cleanup commit - it's not part of the changes for the feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

if (!categories.contains(label))
categories[label] = "";
}
setValue("BitTorrent/Session/Categories", categories);
SettingsStorage::instance()->removeValue("TransferListFilters/customLabels");
}
Expand Down
22 changes: 12 additions & 10 deletions src/base/preferences.h
Expand Up @@ -89,27 +89,33 @@ class Preferences: public QObject
const QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
void setValue(const QString &key, const QVariant &value);

static Preferences* m_instance;
static Preferences *m_instance;

signals:
void changed();

public:
static void initInstance();
static void freeInstance();
static Preferences* instance();
static Preferences *instance();

// General options
// Appearance options
QString getLocale() const;
void setLocale(const QString &locale);
bool useAlternatingRowColors() const;
void setAlternatingRowColors(bool b);
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
bool useSystemIconTheme() const;
void setSystemIconTheme(bool enabled);
#endif

// General options
bool deleteTorrentFilesAsDefault() const;
void setDeleteTorrentFilesAsDefault(bool del);
bool confirmOnExit() const;
void setConfirmOnExit(bool confirm);
bool speedInTitleBar() const;
void showSpeedInTitleBar(bool show);
bool useAlternatingRowColors() const;
void setAlternatingRowColors(bool b);
bool getHideZeroValues() const;
void setHideZeroValues(bool b);
int getHideZeroComboValues() const;
Expand Down Expand Up @@ -226,10 +232,6 @@ class Preferences: public QObject
void resolvePeerCountries(bool resolve);
bool resolvePeerHostNames() const;
void resolvePeerHostNames(bool resolve);
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
bool useSystemIconTheme() const;
void useSystemIconTheme(bool enabled);
#endif
bool recursiveDownloadDisabled() const;
void disableRecursiveDownload(bool disable = true);
#ifdef Q_OS_WIN
Expand Down Expand Up @@ -332,7 +334,7 @@ class Preferences: public QObject
int getToolbarTextPosition() const;
void setToolbarTextPosition(const int position);

//From old RssSettings class
// From old RssSettings class
bool isRSSEnabled() const;
void setRSSEnabled(const bool enabled);
uint getRSSRefreshInterval() const;
Expand Down
11 changes: 0 additions & 11 deletions src/gui/advancedsettings.cpp
Expand Up @@ -67,9 +67,6 @@ enum AdvSettingsRows
PROGRAM_NOTIFICATIONS,
TORRENT_ADDED_NOTIFICATIONS,
DOWNLOAD_TRACKER_FAVICON,
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
USE_ICON_THEME,
#endif

// libtorrent section
LIBTORRENT_HEADER,
Expand Down Expand Up @@ -179,10 +176,6 @@ void AdvancedSettings::saveAdvancedSettings()
pref->setTrackerPort(spin_tracker_port.value());
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
pref->setUpdateCheckEnabled(cb_update_check.isChecked());
#endif
// Icon theme
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
pref->useSystemIconTheme(cb_use_icon_theme.isChecked());
#endif
pref->setConfirmTorrentRecheck(cb_confirm_torrent_recheck.isChecked());
session->setAnnounceToAllTrackers(cb_announce_all_trackers.isChecked());
Expand Down Expand Up @@ -369,10 +362,6 @@ void AdvancedSettings::loadAdvancedSettings()
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
cb_update_check.setChecked(pref->isUpdateCheckEnabled());
addRow(UPDATE_CHECK, tr("Check for software updates"), &cb_update_check);
#endif
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
cb_use_icon_theme.setChecked(pref->useSystemIconTheme());
addRow(USE_ICON_THEME, tr("Use system icon theme"), &cb_use_icon_theme);
#endif
// Torrent recheck confirmation
cb_confirm_torrent_recheck.setChecked(pref->confirmTorrentRecheck());
Expand Down
4 changes: 0 additions & 4 deletions src/gui/advancedsettings.h
Expand Up @@ -87,10 +87,6 @@ private slots:
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
QCheckBox cb_update_check;
#endif

#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
QCheckBox cb_use_icon_theme;
#endif
};

#endif // ADVANCEDSETTINGS_H
6 changes: 4 additions & 2 deletions src/gui/guiiconprovider.cpp
Expand Up @@ -43,7 +43,9 @@ GuiIconProvider::GuiIconProvider(QObject *parent)
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure()));
}

GuiIconProvider::~GuiIconProvider() {}
GuiIconProvider::~GuiIconProvider()
{
}

void GuiIconProvider::initInstance()
{
Expand Down Expand Up @@ -117,6 +119,7 @@ QIcon GuiIconProvider::generateDifferentSizes(const QIcon &icon)

return newIcon;
}

#endif

QString GuiIconProvider::getIconPath(const QString &iconId)
Expand All @@ -138,7 +141,6 @@ QString GuiIconProvider::getIconPath(const QString &iconId)
return IconProvider::getIconPath(iconId);
}


void GuiIconProvider::configure()
{
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
Expand Down
2 changes: 1 addition & 1 deletion src/gui/mainwindow.cpp
Expand Up @@ -776,7 +776,7 @@ void MainWindow::createKeyboardShortcuts()
m_ui->actionDocumentation->setShortcut(QKeySequence::HelpContents);
m_ui->actionOptions->setShortcut(Qt::ALT + Qt::Key_O);
m_ui->actionStart->setShortcut(Qt::CTRL + Qt::Key_S);
m_ui->actionStartAll->setShortcut(Qt::CTRL + Qt::SHIFT +Qt::Key_S);
m_ui->actionStartAll->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_S);
m_ui->actionPause->setShortcut(Qt::CTRL + Qt::Key_P);
m_ui->actionPauseAll->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_P);
m_ui->actionBottomPriority->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Minus);
Expand Down