Limit both QSettings reads and writes (#6057)
Any access, read or write, via QSettings requires locking `Clementine.conf`. On some devices, this can be slow. Moreover, it also increases power use and wear on devices such as SSDs. To improve the situation, defer QSettings updates until program close for window resize, current playlist tab, and playlist geometry, i.e. `PlaylistView::SaveGeometry`. Also, limit `PlaylistView::LoadGeometry` to once per program run. Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
This commit is contained in:
parent
f00d9727c3
commit
6a312e7459
@ -94,7 +94,6 @@ PlaylistContainer::PlaylistContainer(QWidget* parent)
|
||||
ui_->tab_bar->setMaximumHeight(0);
|
||||
|
||||
// Connections
|
||||
connect(ui_->tab_bar, SIGNAL(currentChanged(int)), SLOT(Save()));
|
||||
connect(ui_->tab_bar, SIGNAL(Save(int)), SLOT(SavePlaylist(int)));
|
||||
|
||||
// set up timer for delayed filter updates
|
||||
@ -109,7 +108,10 @@ PlaylistContainer::PlaylistContainer(QWidget* parent)
|
||||
ui_->filter->installEventFilter(this);
|
||||
}
|
||||
|
||||
PlaylistContainer::~PlaylistContainer() { delete ui_; }
|
||||
PlaylistContainer::~PlaylistContainer() {
|
||||
Save();
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
PlaylistView* PlaylistContainer::view() const { return ui_->playlist; }
|
||||
|
||||
|
@ -113,6 +113,7 @@ PlaylistView::PlaylistView(QWidget* parent)
|
||||
upgrading_from_qheaderview_(false),
|
||||
read_only_settings_(true),
|
||||
upgrading_from_version_(-1),
|
||||
header_loaded_(false),
|
||||
background_initialized_(false),
|
||||
background_image_type_(Default),
|
||||
blur_radius_(kDefaultBlurRadius),
|
||||
@ -148,12 +149,6 @@ PlaylistView::PlaylistView(QWidget* parent)
|
||||
currenttrack_pause_ =
|
||||
currenttrack_pause.pixmap(currenttrack_pause.actualSize(QSize(32, 32)));
|
||||
|
||||
connect(header_, SIGNAL(sectionResized(int, int, int)), SLOT(SaveGeometry()));
|
||||
connect(header_, SIGNAL(sectionMoved(int, int, int)), SLOT(SaveGeometry()));
|
||||
connect(header_, SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
|
||||
SLOT(SaveGeometry()));
|
||||
connect(header_, SIGNAL(SectionVisibilityChanged(int, bool)),
|
||||
SLOT(SaveGeometry()));
|
||||
connect(header_, SIGNAL(SectionRatingLockStatusChanged(bool)),
|
||||
SLOT(SetRatingLockStatus(bool)));
|
||||
connect(header_, SIGNAL(sectionResized(int, int, int)),
|
||||
@ -190,6 +185,11 @@ PlaylistView::PlaylistView(QWidget* parent)
|
||||
fade_animation_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0
|
||||
}
|
||||
|
||||
PlaylistView::~PlaylistView() {
|
||||
SaveGeometry();
|
||||
delete style_;
|
||||
}
|
||||
|
||||
void PlaylistView::SetApplication(Application* app) {
|
||||
Q_ASSERT(app);
|
||||
app_ = app;
|
||||
@ -281,7 +281,7 @@ void PlaylistView::SetPlaylist(Playlist* playlist) {
|
||||
}
|
||||
|
||||
playlist_ = playlist;
|
||||
LoadGeometry();
|
||||
if (!header_loaded_) LoadGeometry();
|
||||
LoadRatingLockStatus();
|
||||
ReloadSettings();
|
||||
DynamicModeChanged(playlist->is_dynamic());
|
||||
@ -326,6 +326,7 @@ void PlaylistView::setModel(QAbstractItemModel* m) {
|
||||
|
||||
void PlaylistView::LoadGeometry() {
|
||||
QSettings settings;
|
||||
header_loaded_ = true;
|
||||
settings.beginGroup(Playlist::kSettingsGroup);
|
||||
|
||||
QByteArray state(settings.value("state").toByteArray());
|
||||
@ -1177,7 +1178,6 @@ void PlaylistView::SaveSettings() {
|
||||
void PlaylistView::StretchChanged(bool stretch) {
|
||||
setHorizontalScrollBarPolicy(stretch ? Qt::ScrollBarAlwaysOff
|
||||
: Qt::ScrollBarAsNeeded);
|
||||
SaveGeometry();
|
||||
}
|
||||
|
||||
void PlaylistView::DynamicModeChanged(bool dynamic) {
|
||||
|
@ -57,6 +57,8 @@ class PlaylistProxyStyle : public QProxyStyle {
|
||||
class PlaylistView : public QTreeView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
~PlaylistView();
|
||||
|
||||
enum BackgroundImageType { Default, None, Custom, AlbumCover };
|
||||
|
||||
PlaylistView(QWidget* parent = nullptr);
|
||||
@ -194,6 +196,7 @@ signals:
|
||||
bool upgrading_from_qheaderview_;
|
||||
bool read_only_settings_;
|
||||
int upgrading_from_version_;
|
||||
bool header_loaded_;
|
||||
|
||||
bool background_initialized_;
|
||||
BackgroundImageType background_image_type_;
|
||||
|
@ -865,11 +865,6 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
|
||||
connect(global_shortcuts_, SIGNAL(RemoveCurrentSong()),
|
||||
app_->playlist_manager(), SLOT(RemoveCurrentSong()));
|
||||
|
||||
// Fancy tabs
|
||||
connect(ui_->tabs, SIGNAL(ModeChanged(FancyTabWidget::Mode)),
|
||||
SLOT(SaveGeometry()));
|
||||
connect(ui_->tabs, SIGNAL(CurrentChanged(int)), SLOT(SaveGeometry()));
|
||||
|
||||
// Lyrics
|
||||
ConnectInfoView(song_info_view_);
|
||||
ConnectInfoView(artist_info_view_);
|
||||
@ -1261,8 +1256,6 @@ void MainWindow::ScrobbleButtonVisibilityChanged(bool value) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent*) { SaveGeometry(); }
|
||||
|
||||
void MainWindow::SaveGeometry() {
|
||||
was_maximized_ = isMaximized();
|
||||
settings_.setValue("maximized", was_maximized_);
|
||||
|
@ -131,7 +131,6 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
void closeEvent(QCloseEvent* event);
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
|
Loading…
x
Reference in New Issue
Block a user