Source code maintenance

Memory leaks:
- NotifyQt::UpdateGUI -> popup messages (toaster) stay hidden in memory
- p3disc::handleIncoming -> item was not deleted when RsDiscHeartbeat (memory leak every tick)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2852 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-05-05 22:03:43 +00:00
parent 03fa79eda0
commit c3d92dc472
11 changed files with 124 additions and 97 deletions

View File

@ -173,6 +173,7 @@ int p3disc::handleIncoming()
}
else if (NULL != (dta = dynamic_cast<RsDiscHeartbeat *> (item))) {
recvHeartbeatMsg(dta);
delete item;
return 1;
}
delete item;

View File

@ -49,8 +49,11 @@ MessagesPopupDialog::MessagesPopupDialog(QWidget* parent, Qt::WFlags flags)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
setAttribute ( Qt::WA_DeleteOnClose, true );
messagesdlg = new MessagesDialog();
messagesdlg->setAttribute ( Qt::WA_DeleteOnClose, true );
QVBoxLayout *layout = new QVBoxLayout(ui.centralwidget);
layout->addWidget(messagesdlg);

View File

@ -365,7 +365,7 @@ void NetworkDialog::insertConnect()
std::string gpg_widget_id = (connectWidget->topLevelItem(index))->text(4).toStdString();
RsPeerDetails detail;
if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || (detail.validLvl < 3 && !detail.accept_connection)) {
delete connectWidget->takeTopLevelItem(index);
delete (connectWidget->takeTopLevelItem(index));
} else {
index++;
}
@ -375,7 +375,7 @@ void NetworkDialog::insertConnect()
std::string gpg_widget_id = (ui.unvalidGPGkeyWidget->topLevelItem(index))->text(4).toStdString();
RsPeerDetails detail;
if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || detail.validLvl >= 3 || detail.accept_connection) {
delete ui.unvalidGPGkeyWidget->takeTopLevelItem(index);
delete (ui.unvalidGPGkeyWidget->takeTopLevelItem(index));
} else {
index++;
}

View File

@ -18,61 +18,61 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "CallToaster.h"
#include "QtToaster.h"
#include "ui_CallToaster.h"
#include "ui_CallToaster.h"
//#include <util/SafeDelete.h>
//#include <util/SafeConnect.h>
#include <QtGui/QtGui>
CallToaster::CallToaster()
: QObject(NULL) {
_callToasterWidget = new QWidget(NULL);
_ui = new Ui::CallToaster();
_ui->setupUi(_callToasterWidget);
_ui->hangUpButton->setPixmaps(QPixmap(":/images/toaster/hangup.png"),
QPixmap(),
QPixmap(),
QPixmap(":/images/toaster/hangup.png"),
QPixmap(),
QPixmap());
_ui->pickUpButton->setPixmaps(QPixmap(":/images/toaster/pickup.png"),
QPixmap(),
QPixmap(),
QPixmap(":/images/toaster/pickup.png"),
QPixmap(),
QPixmap());
_ui->pickUpButton->setMinimumSize(QSize(48, 56));
_ui = new Ui::CallToaster();
_ui->setupUi(_callToasterWidget);
_ui->hangUpButton->setPixmaps(QPixmap(":/images/toaster/hangup.png"),
QPixmap(),
QPixmap(),
QPixmap(":/images/toaster/hangup.png"),
QPixmap(),
QPixmap());
_ui->pickUpButton->setPixmaps(QPixmap(":/images/toaster/pickup.png"),
QPixmap(),
QPixmap(),
QPixmap(":/images/toaster/pickup.png"),
QPixmap(),
QPixmap());
_ui->pickUpButton->setMinimumSize(QSize(48, 56));
_ui->pickUpButton->setMaximumSize(QSize(48, 56));
connect(_ui->pickUpButton, SIGNAL(clicked()), SLOT(pickUpButtonSlot()));
_ui->hangUpButton->setMinimumSize(QSize(28, 56));
_ui->hangUpButton->setMaximumSize(QSize(28, 56));
connect(_ui->pickUpButton, SIGNAL(clicked()), SLOT(pickUpButtonSlot()));
_ui->hangUpButton->setMinimumSize(QSize(28, 56));
_ui->hangUpButton->setMaximumSize(QSize(28, 56));
connect(_ui->hangUpButton, SIGNAL(clicked()), SLOT(hangUpButtonSlot()));
connect(_ui->closeButton, SIGNAL(clicked()), SLOT(close()));
_toaster = new QtToaster(_callToasterWidget, _ui->windowFrame);
_toaster->setTimeOnTop(10000);
}
_toaster = new QtToaster(this, _callToasterWidget, _ui->windowFrame);
_toaster->setTimeOnTop(10000);
}
CallToaster::~CallToaster() {
delete(_ui);
}
void CallToaster::setMessage(const QString & message) {
_ui->messageLabel->setText(message);
}
void CallToaster::setMessage(const QString & message) {
_ui->messageLabel->setText(message);
}
void CallToaster::setPixmap(const QPixmap & pixmap) {
_ui->pixmapLabel->setPixmap(pixmap);
@ -80,18 +80,18 @@ void CallToaster::setPixmap(const QPixmap & pixmap) {
void CallToaster::show() {
_toaster->show();
}
}
void CallToaster::close() {
_toaster->close();
}
void CallToaster::hangUpButtonSlot() {
hangUpButtonClicked();
close();
}
void CallToaster::pickUpButtonSlot() {
pickUpButtonClicked();
close();
}
void CallToaster::hangUpButtonSlot() {
hangUpButtonClicked();
close();
}
void CallToaster::pickUpButtonSlot() {
pickUpButtonClicked();
close();
}

View File

@ -18,23 +18,23 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "ChatToaster.h"
#include "ui_ChatToaster.h"
#include "QtToaster.h"
#include <QtGui/QtGui>
ChatToaster::ChatToaster()
: QObject(NULL) {
_chatToasterWidget = new QWidget(NULL);
_ui = new Ui::ChatToaster();
_ui->setupUi(_chatToasterWidget);
_ui = new Ui::ChatToaster();
_ui->setupUi(_chatToasterWidget);
_ui->chatButton->setPixmaps(QPixmap(":/images/toaster/chat.png"),
QPixmap(),
@ -42,22 +42,22 @@ ChatToaster::ChatToaster()
QPixmap(":/images/toaster/chat.png"),
QPixmap(),
QPixmap());
connect(_ui->chatButton, SIGNAL(clicked()), SLOT(chatButtonSlot()));
connect(_ui->closeButton, SIGNAL(clicked()), SLOT(close()));
_toaster = new QtToaster(_chatToasterWidget, _ui->windowFrame);
_toaster->setTimeOnTop(5000);
}
_toaster = new QtToaster(this, _chatToasterWidget, _ui->windowFrame);
_toaster->setTimeOnTop(5000);
}
ChatToaster::~ChatToaster() {
delete(_ui);
}
void ChatToaster::setMessage(const QString & message) {
_ui->messageLabel->setText(message);
}
void ChatToaster::setMessage(const QString & message) {
_ui->messageLabel->setText(message);
}
void ChatToaster::setPixmap(const QPixmap & pixmap) {
_ui->pixmapLabel->setPixmap(pixmap);
@ -66,12 +66,12 @@ void ChatToaster::setPixmap(const QPixmap & pixmap) {
void ChatToaster::show() {
_toaster->show();
}
void ChatToaster::close() {
_toaster->close();
}
void ChatToaster::chatButtonSlot() {
chatButtonClicked();
close();
}
void ChatToaster::close() {
_toaster->close();
}
void ChatToaster::chatButtonSlot() {
chatButtonClicked();
close();
}

View File

@ -37,7 +37,7 @@ ForumsToaster::ForumsToaster()
connect(_ui->closeButton, SIGNAL(clicked()), SLOT(close()));
_toaster = new QtToaster(_ForumsToasterWidget, _ui->windowFrame);
_toaster = new QtToaster(this, _ForumsToasterWidget, _ui->windowFrame);
_toaster->setTimeOnTop(5000);
}

View File

@ -37,7 +37,7 @@ GroupChatToaster::GroupChatToaster()
connect(_ui->closeButton, SIGNAL(clicked()), SLOT(close()));
_toaster = new QtToaster(_GroupChatToasterWidget, _ui->windowFrame);
_toaster = new QtToaster(this, _GroupChatToasterWidget, _ui->windowFrame);
_toaster->setTimeOnTop(5000);
}

View File

@ -24,7 +24,10 @@ MessageToaster::MessageToaster( QWidget * parent, Qt::WFlags f)
: QWidget(parent, f)
{
setupUi(this);
// set window flags
setAttribute ( Qt::WA_DeleteOnClose, true );
// set window flags
QWidget::setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint);
// init the timer
displayTimer = new QTimer(this);
@ -45,7 +48,10 @@ MessageToaster::~MessageToaster()
void MessageToaster::displayTimerOnTimer()
{
if (!isVisible()) return;
if (!isVisible()) {
close();
return;
}
QDesktopWidget *desktop = QApplication::desktop();
QRect availableGeometry = desktop->availableGeometry(this);
@ -68,6 +74,7 @@ void MessageToaster::displayTimerOnTimer()
displayState = dsWaiting;
displayTimer->stop();
hide();
close();
}
else if (displayState == dsWaiting)
{
@ -97,8 +104,10 @@ void MessageToaster::closeClicked()
void MessageToaster::openmessageClicked()
{
static MessagesPopupDialog *msgdialog = new MessagesPopupDialog();
MessagesPopupDialog *msgdialog = new MessagesPopupDialog();
msgdialog->show();
/* window will destroy itself! */
}
void MessageToaster::setMessage(const QString & message)

View File

@ -37,7 +37,7 @@ OnlineToaster::OnlineToaster()
connect(_ui->closeButton, SIGNAL(clicked()), SLOT(close()));
_toaster = new QtToaster(_onlineToasterWidget, _ui->windowFrame);
_toaster = new QtToaster(this, _onlineToasterWidget, _ui->windowFrame);
_toaster->setTimeOnTop(5000);
}

View File

@ -28,7 +28,7 @@
static const unsigned TIME_TO_SHOW = 20;
QtToaster::QtToaster(QWidget * toaster, QFrame * toasterWindowFrame)
QtToaster::QtToaster(QObject *master, QWidget * toaster, QFrame * toasterWindowFrame)
: QObject(toaster) {
_timer = NULL;
@ -36,14 +36,23 @@ QtToaster::QtToaster(QWidget * toaster, QFrame * toasterWindowFrame)
_toaster = toaster;
_toaster->setParent(_toaster->parentWidget(), Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
_toaster->setWindowFlags(_toaster->windowFlags() | Qt::ToolTip);
WidgetBackgroundImage::setBackgroundImage(toasterWindowFrame, ":images/toaster/toaster-backrs4.png", WidgetBackgroundImage::AdjustSize);
_toaster->setWindowFlags(_toaster->windowFlags() | Qt::ToolTip);
_toaster->setAttribute ( Qt::WA_DeleteOnClose, true );
_master = master;
WidgetBackgroundImage::setBackgroundImage(toasterWindowFrame, ":images/toaster/toaster-backrs4.png", WidgetBackgroundImage::AdjustSize);
_toaster->resize(184, 128);
}
QtToaster::~QtToaster()
{
if (_master) {
delete (_master);
}
}
void QtToaster::setTimeOnTop(unsigned time) {
_timeOnTop = time;
}
@ -53,6 +62,8 @@ void QtToaster::close() {
_timer->stop();
}
_toaster->close();
delete (this);
}
void QtToaster::show() {

View File

@ -18,9 +18,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef QTTOASTER_H
#define QTTOASTER_H
#ifndef QTTOASTER_H
#define QTTOASTER_H
#include <QtCore/QObject>
@ -34,12 +34,13 @@ class QFrame;
* This class helps factorizing the code between QtCallToaster and QtChatToaster.
*
*
*/
class QtToaster : public QObject {
Q_OBJECT
public:
QtToaster(QWidget * toaster, QFrame * toasterWindowFrame);
*/
class QtToaster : public QObject {
Q_OBJECT
public:
QtToaster(QObject *master, QWidget * toaster, QFrame * toasterWindowFrame);
~QtToaster();
/**
* Sets the time with the toaster on top.
@ -55,16 +56,18 @@ public:
private Q_SLOTS:
void changeToasterPosition();
private:
private:
QWidget * _toaster;
QTimer * _timer;
QObject *_master;
QTimer * _timer;
bool _show;
unsigned _timeOnTop;
};
#endif //QTTOASTER_H
unsigned _timeOnTop;
};
#endif //QTTOASTER_H