Merge pull request #59 from namecheap/bugfix/RND-661-flameshot-memory-leaks
Bugfix/rnd 661 flameshot memory leaks
This commit is contained in:
@@ -33,8 +33,6 @@
|
||||
#include <QScreen>
|
||||
#endif
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
ShortcutsWidget::ShortcutsWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
Controller::Controller()
|
||||
: m_captureWindow(nullptr)
|
||||
{
|
||||
m_history = nullptr;
|
||||
|
||||
qApp->setQuitOnLastWindowClosed(false);
|
||||
|
||||
// set default shortcusts if not set yet
|
||||
@@ -68,6 +70,11 @@ Controller::Controller()
|
||||
qApp->setStyleSheet(StyleSheet);
|
||||
}
|
||||
|
||||
Controller::~Controller()
|
||||
{
|
||||
delete m_history;
|
||||
}
|
||||
|
||||
Controller* Controller::getInstance()
|
||||
{
|
||||
static Controller c;
|
||||
@@ -297,8 +304,11 @@ void Controller::updateConfigComponents()
|
||||
|
||||
void Controller::showRecentScreenshots()
|
||||
{
|
||||
HistoryWidget* pHistory = new HistoryWidget();
|
||||
pHistory->exec();
|
||||
if (nullptr == m_history) {
|
||||
m_history = new HistoryWidget();
|
||||
}
|
||||
m_history->loadHistory();
|
||||
m_history->show();
|
||||
}
|
||||
|
||||
void Controller::startFullscreenCapture(const uint id)
|
||||
|
||||
@@ -30,6 +30,7 @@ class ConfigWindow;
|
||||
class InfoWindow;
|
||||
class QSystemTrayIcon;
|
||||
class CaptureLauncher;
|
||||
class HistoryWidget;
|
||||
using lambda = std::function<void(void)>;
|
||||
|
||||
class Controller : public QObject
|
||||
@@ -40,6 +41,7 @@ public:
|
||||
static Controller* getInstance();
|
||||
|
||||
Controller(const Controller&) = delete;
|
||||
~Controller();
|
||||
void operator=(const Controller&) = delete;
|
||||
|
||||
void enableExports();
|
||||
@@ -87,4 +89,6 @@ private:
|
||||
QPointer<CaptureLauncher> m_launcherWindow;
|
||||
QPointer<ConfigWindow> m_configWindow;
|
||||
QPointer<QSystemTrayIcon> m_trayIcon;
|
||||
|
||||
HistoryWidget* m_history;
|
||||
};
|
||||
|
||||
@@ -17,14 +17,11 @@
|
||||
|
||||
#include "globalshortcutfilter.h"
|
||||
#include "src/core/controller.h"
|
||||
#include "src/widgets/historywidget.h"
|
||||
#include <qt_windows.h>
|
||||
|
||||
GlobalShortcutFilter::GlobalShortcutFilter(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_history = nullptr;
|
||||
|
||||
// Forced Print Screen
|
||||
if (RegisterHotKey(NULL, 1, 0, VK_SNAPSHOT)) {
|
||||
// ok - capture screen
|
||||
@@ -35,11 +32,6 @@ GlobalShortcutFilter::GlobalShortcutFilter(QObject* parent)
|
||||
}
|
||||
}
|
||||
|
||||
GlobalShortcutFilter::~GlobalShortcutFilter()
|
||||
{
|
||||
delete m_history;
|
||||
}
|
||||
|
||||
bool GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType,
|
||||
void* message,
|
||||
long* result)
|
||||
@@ -56,10 +48,7 @@ bool GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType,
|
||||
|
||||
// Show screenshots history
|
||||
if (VK_SNAPSHOT == keycode && MOD_SHIFT == modifiers) {
|
||||
if (m_history == nullptr) {
|
||||
m_history = new HistoryWidget();
|
||||
}
|
||||
m_history->show();
|
||||
Controller::getInstance()->showRecentScreenshots();
|
||||
}
|
||||
|
||||
// Capture screen
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
#include <QAbstractNativeEventFilter>
|
||||
#include <QObject>
|
||||
|
||||
class HistoryWidget;
|
||||
|
||||
class GlobalShortcutFilter
|
||||
: public QObject
|
||||
, public QAbstractNativeEventFilter
|
||||
@@ -29,7 +27,6 @@ class GlobalShortcutFilter
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GlobalShortcutFilter(QObject* parent = nullptr);
|
||||
~GlobalShortcutFilter();
|
||||
|
||||
bool nativeEventFilter(const QByteArray& eventType,
|
||||
void* message,
|
||||
@@ -43,5 +40,4 @@ private:
|
||||
quint32 nativeKeycode(Qt::Key key);
|
||||
bool registerShortcut(quint32 nativeKey, quint32 nativeMods);
|
||||
bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods);
|
||||
HistoryWidget* m_history;
|
||||
};
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "configshortcuts.h"
|
||||
#include "src/tools/capturetool.h"
|
||||
#include <QDebug>
|
||||
#include <QVariant>
|
||||
|
||||
ConfigShortcuts::ConfigShortcuts() {}
|
||||
|
||||
// QVector<CaptureToolButton::ButtonType> getButtons()
|
||||
|
||||
const QVector<QStringList>& ConfigShortcuts::captureShortcutsDefault(
|
||||
const QVector<CaptureToolButton::ButtonType>& buttons)
|
||||
{
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
#include <QUrl>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
HistoryWidget::HistoryWidget(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
@@ -41,8 +39,6 @@ HistoryWidget::HistoryWidget(QWidget* parent)
|
||||
QWidget* widget = new QWidget();
|
||||
scrollArea->setWidget(widget);
|
||||
widget->setLayout(m_pVBox);
|
||||
|
||||
loadHistory();
|
||||
}
|
||||
|
||||
HistoryWidget::~HistoryWidget()
|
||||
@@ -50,8 +46,26 @@ HistoryWidget::~HistoryWidget()
|
||||
delete m_notification;
|
||||
}
|
||||
|
||||
void HistoryWidget::clearHistoryLayout(QLayout* layout)
|
||||
{
|
||||
QLayoutItem* child;
|
||||
while (layout->count() != 0) {
|
||||
child = layout->takeAt(0);
|
||||
if (child->layout() != 0) {
|
||||
clearHistoryLayout(child->layout());
|
||||
} else if (child->widget() != 0) {
|
||||
delete child->widget();
|
||||
}
|
||||
|
||||
delete child;
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::loadHistory()
|
||||
{
|
||||
// clear old history if exists
|
||||
clearHistoryLayout(m_pVBox);
|
||||
|
||||
// read history files
|
||||
History history = History();
|
||||
QList<QString> historyFiles = history.history();
|
||||
|
||||
@@ -21,10 +21,11 @@ public:
|
||||
explicit HistoryWidget(QWidget* parent = nullptr);
|
||||
~HistoryWidget();
|
||||
|
||||
signals:
|
||||
void loadHistory();
|
||||
|
||||
private:
|
||||
void loadHistory();
|
||||
void clearHistoryLayout(QLayout* layout);
|
||||
|
||||
void addLine(const QString&, const QString&);
|
||||
void setEmptyMessage();
|
||||
void removeItem(QLayout* pl,
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
// Based on https://stackoverflow.com/a/53135675/964478
|
||||
|
||||
#include "orientablepushbutton.h"
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionButton>
|
||||
#include <QStylePainter>
|
||||
|
||||
Reference in New Issue
Block a user