fix: qt client memory leaks (#1378)
* fix: don't leak the qt client's QFileSystemWatcher * fix: don't leak the Qt client's ListViewProxyStyle
This commit is contained in:
parent
77ced2b7c8
commit
49400ab443
|
@ -142,6 +142,7 @@ MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool
|
||||||
session_(session),
|
session_(session),
|
||||||
prefs_(prefs),
|
prefs_(prefs),
|
||||||
model_(model),
|
model_(model),
|
||||||
|
lvp_style_(new ListViewProxyStyle{}),
|
||||||
filter_model_(prefs),
|
filter_model_(prefs),
|
||||||
torrent_delegate_(new TorrentDelegate(this)),
|
torrent_delegate_(new TorrentDelegate(this)),
|
||||||
torrent_delegate_min_(new TorrentDelegateMin(this)),
|
torrent_delegate_min_(new TorrentDelegateMin(this)),
|
||||||
|
@ -155,7 +156,7 @@ MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool
|
||||||
|
|
||||||
ui_.setupUi(this);
|
ui_.setupUi(this);
|
||||||
|
|
||||||
ui_.listView->setStyle(new ListViewProxyStyle);
|
ui_.listView->setStyle(lvp_style_.get());
|
||||||
ui_.listView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
ui_.listView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
|
|
||||||
// icons
|
// icons
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
@ -32,6 +33,7 @@ class QStringList;
|
||||||
class AboutDialog;
|
class AboutDialog;
|
||||||
class AddData;
|
class AddData;
|
||||||
class DetailsDialog;
|
class DetailsDialog;
|
||||||
|
class ListViewProxyStyle;
|
||||||
class Prefs;
|
class Prefs;
|
||||||
class PrefsDialog;
|
class PrefsDialog;
|
||||||
class Session;
|
class Session;
|
||||||
|
@ -142,6 +144,8 @@ private:
|
||||||
Prefs& prefs_;
|
Prefs& prefs_;
|
||||||
TorrentModel& model_;
|
TorrentModel& model_;
|
||||||
|
|
||||||
|
std::shared_ptr<ListViewProxyStyle> lvp_style_;
|
||||||
|
|
||||||
QPixmap pixmap_network_error_;
|
QPixmap pixmap_network_error_;
|
||||||
QPixmap pixmap_network_idle_;
|
QPixmap pixmap_network_idle_;
|
||||||
QPixmap pixmap_network_receive_;
|
QPixmap pixmap_network_receive_;
|
||||||
|
|
|
@ -81,20 +81,13 @@ void WatchDir::setPath(QString const& path, bool is_enabled)
|
||||||
{
|
{
|
||||||
// clear out any remnants of the previous watcher, if any
|
// clear out any remnants of the previous watcher, if any
|
||||||
watch_dir_files_.clear();
|
watch_dir_files_.clear();
|
||||||
|
watcher_.reset();
|
||||||
if (watcher_ != nullptr)
|
|
||||||
{
|
|
||||||
delete watcher_;
|
|
||||||
watcher_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// maybe create a new watcher
|
// maybe create a new watcher
|
||||||
if (is_enabled)
|
if (is_enabled)
|
||||||
{
|
{
|
||||||
watcher_ = new QFileSystemWatcher();
|
watcher_ = std::make_unique<QFileSystemWatcher>(QStringList{ path });
|
||||||
watcher_->addPath(path);
|
connect(watcher_.get(), SIGNAL(directoryChanged(QString)), this, SLOT(watcherActivated(QString)));
|
||||||
connect(watcher_, SIGNAL(directoryChanged(QString)), this, SLOT(watcherActivated(QString)));
|
|
||||||
// std::cerr << "watching " << qPrintable(path) << " for new .torrent files" << std::endl;
|
|
||||||
QTimer::singleShot(0, this, SLOT(rescanAllWatchedDirectories())); // trigger the watchdir for .torrent files in there already
|
QTimer::singleShot(0, this, SLOT(rescanAllWatchedDirectories())); // trigger the watchdir for .torrent files in there already
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,12 +143,12 @@ void WatchDir::watcherActivated(QString const& path)
|
||||||
|
|
||||||
void WatchDir::rescanAllWatchedDirectories()
|
void WatchDir::rescanAllWatchedDirectories()
|
||||||
{
|
{
|
||||||
if (watcher_ == nullptr)
|
if (!watcher_)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (QString const& path : watcher_->directories())
|
for (auto const& path : watcher_->directories())
|
||||||
{
|
{
|
||||||
watcherActivated(path);
|
watcherActivated(path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QFileSystemWatcher>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class QFileSystemWatcher;
|
|
||||||
|
|
||||||
class TorrentModel;
|
class TorrentModel;
|
||||||
|
|
||||||
class WatchDir : public QObject
|
class WatchDir : public QObject
|
||||||
|
@ -49,5 +50,5 @@ private:
|
||||||
TorrentModel const& model_;
|
TorrentModel const& model_;
|
||||||
|
|
||||||
QSet<QString> watch_dir_files_;
|
QSet<QString> watch_dir_files_;
|
||||||
QFileSystemWatcher* watcher_ = {};
|
std::unique_ptr<QFileSystemWatcher> watcher_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue