mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #3444
Diadlo (1): fix(chatform, screenshotgrabber): Fixed memory leak
This commit is contained in:
commit
d408cb5184
|
@ -67,7 +67,8 @@
|
||||||
|
|
||||||
ChatForm::ChatForm(Friend* chatFriend)
|
ChatForm::ChatForm(Friend* chatFriend)
|
||||||
: f(chatFriend)
|
: f(chatFriend)
|
||||||
, isTyping{false}
|
, screenshotGrabber(nullptr)
|
||||||
|
, isTyping(false)
|
||||||
{
|
{
|
||||||
Core* core = Core::getInstance();
|
Core* core = Core::getInstance();
|
||||||
coreav = core->getAv();
|
coreav = core->getAv();
|
||||||
|
@ -208,7 +209,7 @@ void ChatForm::onAttachClicked()
|
||||||
file.close();
|
file.close();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
long long filesize = file.size();
|
qint64 filesize = file.size();
|
||||||
file.close();
|
file.close();
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
|
|
||||||
|
@ -783,9 +784,14 @@ void ChatForm::onScreenshotClicked()
|
||||||
|
|
||||||
void ChatForm::doScreenshot()
|
void ChatForm::doScreenshot()
|
||||||
{
|
{
|
||||||
ScreenshotGrabber* screenshotGrabber = new ScreenshotGrabber(this);
|
if (!screenshotGrabber)
|
||||||
connect(screenshotGrabber, &ScreenshotGrabber::screenshotTaken, this, &ChatForm::onScreenshotTaken);
|
screenshotGrabber = new ScreenshotGrabber(this);
|
||||||
|
|
||||||
|
connect(screenshotGrabber, &ScreenshotGrabber::screenshotTaken,
|
||||||
|
this, &ChatForm::onScreenshotTaken);
|
||||||
|
|
||||||
screenshotGrabber->showGrabber();
|
screenshotGrabber->showGrabber();
|
||||||
|
|
||||||
// Create dir for screenshots
|
// Create dir for screenshots
|
||||||
QDir(Settings::getInstance().getAppDataDirPath()).mkpath("screenshots");
|
QDir(Settings::getInstance().getAppDataDirPath()).mkpath("screenshots");
|
||||||
}
|
}
|
||||||
|
@ -807,16 +813,21 @@ void ChatForm::onScreenshotTaken(const QPixmap &pixmap) {
|
||||||
QMessageBox::warning(this,
|
QMessageBox::warning(this,
|
||||||
tr("Failed to open temporary file", "Temporary file for screenshot"),
|
tr("Failed to open temporary file", "Temporary file for screenshot"),
|
||||||
tr("qTox wasn't able to save the screenshot"));
|
tr("qTox wasn't able to save the screenshot"));
|
||||||
|
|
||||||
|
delete screenshotGrabber;
|
||||||
|
screenshotGrabber = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixmap.save(&file, "PNG");
|
pixmap.save(&file, "PNG");
|
||||||
|
|
||||||
long long filesize = file.size();
|
qint64 filesize = file.size();
|
||||||
file.close();
|
file.close();
|
||||||
QFileInfo fi(file);
|
QFileInfo fi(file);
|
||||||
|
|
||||||
emit sendFile(f->getFriendID(), fi.fileName(), fi.filePath(), filesize);
|
emit sendFile(f->getFriendID(), fi.fileName(), fi.filePath(), filesize);
|
||||||
|
delete screenshotGrabber;
|
||||||
|
screenshotGrabber = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onLoadHistory()
|
void ChatForm::onLoadHistory()
|
||||||
|
|
|
@ -20,13 +20,15 @@
|
||||||
#ifndef CHATFORM_H
|
#ifndef CHATFORM_H
|
||||||
#define CHATFORM_H
|
#define CHATFORM_H
|
||||||
|
|
||||||
#include "genericchatform.h"
|
|
||||||
#include "src/core/corestructs.h"
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
|
#include "genericchatform.h"
|
||||||
|
#include "src/core/corestructs.h"
|
||||||
|
#include "src/widget/tool/screenshotgrabber.h"
|
||||||
|
|
||||||
class Friend;
|
class Friend;
|
||||||
class FileTransferInstance;
|
class FileTransferInstance;
|
||||||
class QPixmap;
|
class QPixmap;
|
||||||
|
@ -112,6 +114,7 @@ private:
|
||||||
QAction* loadHistoryAction;
|
QAction* loadHistoryAction;
|
||||||
QAction* copyStatusAction;
|
QAction* copyStatusAction;
|
||||||
|
|
||||||
|
ScreenshotGrabber* screenshotGrabber;
|
||||||
QHash<uint, FileTransferInstance*> ftransWidgets;
|
QHash<uint, FileTransferInstance*> ftransWidgets;
|
||||||
void startCounter();
|
void startCounter();
|
||||||
void stopCounter();
|
void stopCounter();
|
||||||
|
|
|
@ -132,9 +132,10 @@ void ScreenshotGrabber::acceptRegion()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qDebug() << "Screenshot accepted, chosen region" << rect;
|
qDebug() << "Screenshot accepted, chosen region" << rect;
|
||||||
emit screenshotTaken(this->screenGrab.copy(rect));
|
QPixmap pixmap = this->screenGrab.copy(rect);
|
||||||
this->window->close();
|
this->window->close();
|
||||||
restoreHiddenWindows();
|
restoreHiddenWindows();
|
||||||
|
emit screenshotTaken(pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenshotGrabber::setupScene()
|
void ScreenshotGrabber::setupScene()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user