From c7e1a7fa6b003ae40eeb01c5b8f7e5016c7179e3 Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Sat, 29 Nov 2008 16:20:03 +0100 Subject: [PATCH] OTHER: Fix memleak and fixed small bug in hideEvent handlers When promoe was minimized or on a different virtual desktop when it was quit, the visible setting of playlist and equalizer was set to false. So even when those two were visible before switching to a different desktop they where set to closed when promoe was started the next time --- lib/compat.h | 7 +- src/basewindow.cpp | 112 ++++++++++++++++++++++-------- src/basewindow.h | 15 +++- src/equalizer/equalizerwindow.cpp | 28 +------- src/equalizer/equalizerwindow.h | 13 ---- src/mainwindow/mainwindow.cpp | 1 + src/playlist/playlistwindow.cpp | 33 +-------- src/playlist/playlistwindow.h | 8 --- 8 files changed, 105 insertions(+), 112 deletions(-) diff --git a/lib/compat.h b/lib/compat.h index b4d21b0..05cf5a2 100644 --- a/lib/compat.h +++ b/lib/compat.h @@ -38,6 +38,7 @@ inline QString decodeXmmsUrl (const QString &path) { QByteArray p_enc = path.toUtf8 (); + QString ret; #if HAVE_XMMSV // TODO: error checking... xmmsv_t *v_enc = xmmsv_new_string (p_enc.constData ()); @@ -46,15 +47,15 @@ decodeXmmsUrl (const QString &path) const char *p; unsigned int p_len; xmmsv_get_bin (p_dec, reinterpret_cast(&p), &p_len); - QString ret = QString::fromUtf8 (p, p_len); + ret = QString::fromUtf8 (p, p_len); xmmsv_unref (p_dec); // Free p? - return ret; #else char *p_dec = const_cast (xmmsc_result_decode_url (NULL, p_enc.constData ())); - return QString::fromUtf8 (p_dec); + ret = QString::fromUtf8 (p_dec); free (p_dec); #endif + return ret; } diff --git a/src/basewindow.cpp b/src/basewindow.cpp index a31470e..168ab85 100644 --- a/src/basewindow.cpp +++ b/src/basewindow.cpp @@ -19,49 +19,66 @@ #include #include -#include #include +#include + +#include +#include +#include +#include + +#include BaseWindow::BaseWindow (QWidget *parent) : QMainWindow (parent) { } -bool -BaseWindow::touches (QWidget *widget) + +// Qt Event Handlers +void +BaseWindow::hideEvent (QHideEvent *event) { - if (this == widget) { - return true; + if (event->spontaneous ()) { + event->ignore (); + return; } - qint32 left = x (); - qint32 right = left + width (); - qint32 top = y (); - qint32 bottom = top + height (); - - qint32 w_left = widget->x (); - qint32 w_right = w_left + widget->width (); - qint32 w_top = widget->y (); - qint32 w_bottom = w_top + widget->height (); - - if (( (top <= w_bottom) && (bottom >= w_top) && - ((left == w_right || right == w_left)) ) || - ( (left <= w_right) && (right >= w_left) && - ((top == w_bottom) || (bottom == w_top) ) )) { - return true; + if ((objectName ().isEmpty ()) | (objectName () == "MainWindow")) { + event->ignore (); + return; } - return false; + QSettings s; + s.setValue (objectName ()+"/visible", false); + + emit visibilityChanged (false); } -MainWindow * -BaseWindow::mw () +void +BaseWindow::showEvent (QShowEvent *event) { - //MainWindow is the only BaseWindow without a *parent - if (parent ()) { - return qobject_cast(parent ()); - } else { - return qobject_cast(this); + if (objectName ().isEmpty ()) { + event->ignore (); + return; } + + QSettings s; + s.setValue (objectName ()+"/visible", true); + mw ()->attachWidgets (); + + emit visibilityChanged (true); +} + +void +BaseWindow::moveEvent (QMoveEvent *event) +{ + if (objectName ().isEmpty ()) { + event->ignore (); + return; + } + + QSettings s; + s.setValue (objectName ()+"/pos", pos ()); } void @@ -91,6 +108,45 @@ BaseWindow::mouseMoveEvent (QMouseEvent *event) } +// Helper classes vor snapping windows +MainWindow * +BaseWindow::mw () +{ + //MainWindow is the only BaseWindow without a *parent + if (parent ()) { + return qobject_cast(parent ()); + } else { + return qobject_cast(this); + } +} + +bool +BaseWindow::touches (QWidget *widget) +{ + if (this == widget) { + return true; + } + + qint32 left = x (); + qint32 right = left + width (); + qint32 top = y (); + qint32 bottom = top + height (); + + qint32 w_left = widget->x (); + qint32 w_right = w_left + widget->width (); + qint32 w_top = widget->y (); + qint32 w_bottom = w_top + widget->height (); + + if (( (top <= w_bottom) && (bottom >= w_top) && + ((left == w_right || right == w_left)) ) || + ( (left <= w_right) && (right >= w_left) && + ((top == w_bottom) || (bottom == w_top) ) )) { + return true; + } + + return false; +} + QPoint BaseWindow::snapWindow(QPoint pos, AttachedWindowMap attached) { diff --git a/src/basewindow.h b/src/basewindow.h index 4f1f8ea..7870f90 100644 --- a/src/basewindow.h +++ b/src/basewindow.h @@ -20,24 +20,33 @@ #include #include #include -class QMouseEvent; class QPoint; -class MainWindow; +class QHideEvent; +class QShowEvent; +class QMoveEvent; +class QMouseEvent; +class MainWindow; class BaseWindow; typedef QMap AttachedWindowMap; class BaseWindow : public QMainWindow { Q_OBJECT + signals: + void visibilityChanged (bool visible); + public: BaseWindow (QWidget *parent); - + bool touches (QWidget *); MainWindow * mw (); protected: + void hideEvent (QHideEvent *event); + void showEvent (QShowEvent *event); + void moveEvent (QMoveEvent *event); void mousePressEvent (QMouseEvent *event); void mouseReleaseEvent (QMouseEvent *event); void mouseMoveEvent (QMouseEvent *event); diff --git a/src/equalizer/equalizerwindow.cpp b/src/equalizer/equalizerwindow.cpp index 0c1d0b9..c63522c 100644 --- a/src/equalizer/equalizerwindow.cpp +++ b/src/equalizer/equalizerwindow.cpp @@ -17,13 +17,13 @@ #include "QWidget" #include -#include #include "mainwindow.h" #include "equalizerwidget.h" EqualizerWindow::EqualizerWindow (QWidget *parent) : BaseWindow (parent) { + setObjectName ("equalizer"); m_mw = dynamic_cast(parent); setWindowFlags (Qt::Dialog | Qt::FramelessWindowHint); @@ -37,34 +37,8 @@ EqualizerWindow::EqualizerWindow (QWidget *parent) : BaseWindow (parent) setFixedSize (275, 116); } -void -EqualizerWindow::hideEvent (QHideEvent *event) -{ - QSettings s; - s.setValue ("equalizer/visible", false); - - emit visibilityChanged (false); -} - -void -EqualizerWindow::showEvent (QShowEvent *event) -{ - QSettings s; - s.setValue ("equalizer/visible", true); - m_mw->attachWidgets (); - - emit visibilityChanged (true); -} - void EqualizerWindow::setEnabled (void) { qDebug ("test"); } - -void -EqualizerWindow::moveEvent (QMoveEvent *event) -{ - QSettings s; - s.setValue ("equalizer/pos", pos ()); -} diff --git a/src/equalizer/equalizerwindow.h b/src/equalizer/equalizerwindow.h index 3541c4e..073ea3a 100644 --- a/src/equalizer/equalizerwindow.h +++ b/src/equalizer/equalizerwindow.h @@ -19,10 +19,6 @@ #include "basewindow.h" class QWidget; -class QMoveEvent; -class QHideEvent; -class QShowEvent; - class MainWindow; class EqualizerWidget; @@ -33,18 +29,9 @@ class EqualizerWindow : public BaseWindow EqualizerWindow(QWidget *parent); ~EqualizerWindow() {} - signals: - void visibilityChanged(bool visible); - public slots: void setEnabled (void); - protected: - void hideEvent (QHideEvent *event); - void showEvent (QShowEvent *event); - void moveEvent(QMoveEvent *event); - - private: MainWindow *m_mw; EqualizerWidget *m_equalizer; diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index b0fcb6e..0a4496a 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -39,6 +39,7 @@ MainWindow::MainWindow (QWidget *parent) : BaseWindow (parent) { QSettings s; + setWindowTitle (App->applicationName ()); setWindowFlags(Qt::FramelessWindowHint); setMaximumSize (275, 116); #ifndef _WIN32 diff --git a/src/playlist/playlistwindow.cpp b/src/playlist/playlistwindow.cpp index 7cfdff1..acf3750 100644 --- a/src/playlist/playlistwindow.cpp +++ b/src/playlist/playlistwindow.cpp @@ -15,7 +15,6 @@ #include "playlistwindow.h" -#include #include #include #include @@ -27,15 +26,16 @@ PlaylistWindow::PlaylistWindow (QWidget *parent) : BaseWindow (parent) { - QSettings s; + setObjectName ("playlist"); // Name of the config group #ifndef _WIN32 setWindowIcon (QIcon (":icon.png")); #endif + QSettings s; setWindowFlags (Qt::Dialog | Qt::FramelessWindowHint); setAttribute (Qt::WA_DeleteOnClose); - s.beginGroup ("playlist"); + s.beginGroup (objectName ()); if (!s.contains ("size")) { s.setValue ("size", QSize (275, 350)); } @@ -58,26 +58,6 @@ PlaylistWindow::PlaylistWindow (QWidget *parent) : BaseWindow (parent) //setSizeIncrement (25, 29); } -void -PlaylistWindow::hideEvent (QHideEvent *event) -{ - QSettings s; - s.setValue ("playlist/visible", false); - - emit visibilityChanged (false); -} - -void -PlaylistWindow::showEvent (QShowEvent *event) -{ - QSettings s; - s.setValue ("playlist/visible", true); - mw ()->attachWidgets (); - - emit visibilityChanged (true); -} - - void PlaylistWindow::switchDisplay (void) { @@ -119,13 +99,6 @@ PlaylistWindow::resizeEvent (QResizeEvent *event) mw ()->attachWidgets (); } -void -PlaylistWindow::moveEvent (QMoveEvent *event) -{ - QSettings s; - s.setValue ("playlist/pos", pos ()); -} - void PlaylistWindow::enterEvent (QEvent *event) { diff --git a/src/playlist/playlistwindow.h b/src/playlist/playlistwindow.h index bcdd095..7f28cc6 100644 --- a/src/playlist/playlistwindow.h +++ b/src/playlist/playlistwindow.h @@ -20,10 +20,7 @@ #include "basewindow.h" class QEvent; -class QMoveEvent; class QResizeEvent; -class QHideEvent; -class QShowEvent; class QPoint; // our own classes @@ -41,8 +38,6 @@ class PlaylistWindow : public BaseWindow { void setActive (bool); signals: - void visibilityChanged(bool visible); - // setTime is used to set playtime in playlistcontrols void setDisplayTime (int seconds); @@ -50,11 +45,8 @@ class PlaylistWindow : public BaseWindow { void switchDisplay (void); protected: - void hideEvent (QHideEvent *event); - void showEvent (QShowEvent *event); void enterEvent (QEvent *event); void leaveEvent (QEvent *event); - void moveEvent (QMoveEvent *event); void resizeEvent (QResizeEvent *event); private: