Commit 423f5d1b authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen Committed by Jean-Baptiste Kempf

Qt: Use the singleton class, to simplify the code

Use the generic singleton for Bookmarks, ErrorsDialog, extended dialog, GotoTime dialog, every help class, MediaInfo, Messages, OpenURL, Playlist, Plugin, Podcast configuration and VLM. Also fix some memleaks when quitting
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 120a9af2
......@@ -31,8 +31,6 @@
#include <QSpacerItem>
#include <QPushButton>
BookmarksDialog *BookmarksDialog::instance = NULL;
BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf )
{
setWindowFlags( Qt::Tool );
......
......@@ -29,27 +29,15 @@
#include <QStandardItemModel>
#include <QTreeView>
#include <QTreeWidget>
#include "util/singleton.hpp"
class BookmarksDialog : public QVLCFrame
class BookmarksDialog : public QVLCFrame, public Singleton<BookmarksDialog>
{
Q_OBJECT;
public:
static BookmarksDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance )
instance = new BookmarksDialog( p_intf );
return instance;
}
static void killInstance()
{
delete instance;
instance = NULL;
}
private:
BookmarksDialog( intf_thread_t * );
virtual ~BookmarksDialog();
static BookmarksDialog *instance;
QTreeWidget *bookmarksList;
private slots:
......@@ -60,6 +48,8 @@ private slots:
void edit( QTreeWidgetItem *item, int column );
void extract();
void activateItem( QModelIndex index );
friend class Singleton<BookmarksDialog>;
};
#endif
......
......@@ -34,10 +34,8 @@
#include <QDialogButtonBox>
#include <QPushButton>
ErrorsDialog *ErrorsDialog::instance = NULL;
ErrorsDialog::ErrorsDialog( QWidget *parent, intf_thread_t *_p_intf )
: QVLCDialog( parent, _p_intf )
ErrorsDialog::ErrorsDialog( intf_thread_t *_p_intf )
: QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
{
setWindowTitle( qtr( "Errors" ) );
setWindowRole( "vlc-errors" );
......
......@@ -25,29 +25,23 @@
#define QVLC_ERRORS_DIALOG_H_ 1
#include "util/qvlcframe.hpp"
#include "util/singleton.hpp"
class QPushButton;
class QCheckBox;
class QGridLayout;
class QTextEdit;
class ErrorsDialog : public QVLCDialog
class ErrorsDialog : public QVLCDialog, public Singleton<ErrorsDialog>
{
Q_OBJECT;
public:
static ErrorsDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance)
instance = new ErrorsDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
return instance;
}
virtual ~ErrorsDialog() {};
void addError( const QString&, const QString& );
/*void addWarning( QString, QString );*/
private:
ErrorsDialog( QWidget *parent, intf_thread_t * );
static ErrorsDialog *instance;
virtual ~ErrorsDialog() {};
ErrorsDialog( intf_thread_t * );
void add( bool, const QString&, const QString& );
QCheckBox *stopShowing;
......@@ -56,6 +50,8 @@ private slots:
void close();
void clear();
void dontShow();
friend class Singleton<ErrorsDialog>;
};
#endif
......@@ -33,8 +33,6 @@
#include <QTabWidget>
#include <QGridLayout>
ExtendedDialog *ExtendedDialog::instance = NULL;
ExtendedDialog::ExtendedDialog( intf_thread_t *_p_intf ): QVLCFrame( _p_intf )
{
setWindowFlags( Qt::Tool );
......
......@@ -27,38 +27,28 @@
#include "util/qvlcframe.hpp"
#include "components/extended_panels.hpp"
#include "util/singleton.hpp"
class QTabWidget;
class ExtendedDialog : public QVLCFrame
class ExtendedDialog : public QVLCFrame, public Singleton<ExtendedDialog>
{
Q_OBJECT;
public:
static ExtendedDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance)
instance = new ExtendedDialog( p_intf );
return instance;
}
static void killInstance()
{
delete instance;
instance = NULL;
}
void showTab( int i );
int currentTab();
private:
ExtendedDialog( intf_thread_t * );
virtual ~ExtendedDialog();
static ExtendedDialog *instance;
SyncControls *syncW;
ExtVideo *videoEffect;
Equalizer *equal;
QTabWidget *mainTabW;
private slots:
void changedItem( int );
friend class Singleton<ExtendedDialog>;
};
#endif
......
......@@ -34,10 +34,8 @@
#include <QGroupBox>
#include <QDialogButtonBox>
GotoTimeDialog *GotoTimeDialog::instance = NULL;
GotoTimeDialog::GotoTimeDialog( QWidget *parent, intf_thread_t *_p_intf)
: QVLCDialog( parent, _p_intf )
GotoTimeDialog::GotoTimeDialog( intf_thread_t *_p_intf)
: QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
{
setWindowFlags( Qt::Tool );
setWindowTitle( qtr( "Go to Time" ) );
......
......@@ -25,28 +25,22 @@
#define QVLC_GOTOTIME_DIALOG_H_ 1
#include "util/qvlcframe.hpp"
#include "util/singleton.hpp"
class QTimeEdit;
class GotoTimeDialog : public QVLCDialog
class GotoTimeDialog : public QVLCDialog, public Singleton<GotoTimeDialog>
{
Q_OBJECT;
public:
static GotoTimeDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance)
instance = new GotoTimeDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
return instance;
}
virtual ~GotoTimeDialog();
private:
GotoTimeDialog( QWidget *, intf_thread_t * );
static GotoTimeDialog *instance;
GotoTimeDialog( intf_thread_t * );
virtual ~GotoTimeDialog();
QTimeEdit *timeEdit;
private slots:
void close();
void cancel();
friend class Singleton<GotoTimeDialog>;
};
#endif
......@@ -47,8 +47,6 @@
#include <assert.h>
HelpDialog *HelpDialog::instance = NULL;
HelpDialog::HelpDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
{
......@@ -80,10 +78,8 @@ void HelpDialog::close()
toggleVisible();
}
AboutDialog *AboutDialog::instance = NULL;
AboutDialog::AboutDialog( QWidget *parent, intf_thread_t *_p_intf)
: QVLCDialog( parent, _p_intf )
AboutDialog::AboutDialog( intf_thread_t *_p_intf)
: QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
{
setWindowTitle( qtr( "About" ) );
setWindowRole( "vlc-about" );
......@@ -198,8 +194,6 @@ static void UpdateCallback( void *data, bool b_ret )
QApplication::postEvent( UDialog, event );
}
UpdateDialog *UpdateDialog::instance = NULL;
UpdateDialog::UpdateDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
{
setWindowTitle( qtr( "VLC media player updates" ) );
......
......@@ -31,6 +31,7 @@
#include "qt4.hpp"
#include "util/qvlcframe.hpp"
#include "util/singleton.hpp"
class QPushButton;
class QTextBrowser;
......@@ -39,50 +40,32 @@ class QEvent;
class QPushButton;
class QTextEdit;
class HelpDialog : public QVLCFrame
class HelpDialog : public QVLCFrame, public Singleton<HelpDialog>
{
Q_OBJECT;
public:
static HelpDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance)
instance = new HelpDialog( p_intf );
return instance;
}
static void killInstance()
{ delete instance; instance = NULL;}
private:
HelpDialog( intf_thread_t * );
virtual ~HelpDialog();
static HelpDialog *instance;
public slots:
void close();
friend class Singleton<HelpDialog>;
};
class AboutDialog : public QVLCDialog
class AboutDialog : public QVLCDialog, public Singleton<AboutDialog>
{
Q_OBJECT;
public:
static AboutDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance)
instance = new AboutDialog( (QWidget *)p_intf->p_sys->p_mi,
p_intf );
return instance;
}
private:
AboutDialog( QWidget *, intf_thread_t * );
AboutDialog( intf_thread_t * );
virtual ~AboutDialog();
static AboutDialog *instance;
public slots:
void close();
friend class Singleton<AboutDialog>;
};
#ifdef UPDATE_CHECK
......@@ -90,27 +73,16 @@ public slots:
static const int UDOkEvent = QEvent::User + DialogEventType + 21;
static const int UDErrorEvent = QEvent::User + DialogEventType + 22;
class UpdateDialog : public QVLCFrame
class UpdateDialog : public QVLCFrame, public Singleton<UpdateDialog>
{
Q_OBJECT;
public:
static UpdateDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance )
instance = new UpdateDialog( p_intf );
return instance;
}
static void killInstance()
{ delete instance; instance = NULL;}
void updateNotify( bool );
private:
UpdateDialog( intf_thread_t * );
virtual ~UpdateDialog();
static UpdateDialog *instance;
update_t *p_update;
QPushButton *updateButton;
QLabel *updateLabelTop;
......@@ -122,6 +94,8 @@ private:
private slots:
void close();
void UpdateOrDownload();
friend class Singleton<UpdateDialog>;
};
#endif
......
......@@ -34,8 +34,6 @@
#include <QLineEdit>
#include <QLabel>
MediaInfoDialog *MediaInfoDialog::instance = NULL;
/* This Dialog has two main modes:
- General Mode that shows the current Played item, and the stats
- Single mode that shows the info on ONE SINGLE Item on the playlist
......
......@@ -27,27 +27,16 @@
#include "util/qvlcframe.hpp"
#include "components/info_panels.hpp"
#include "util/singleton.hpp"
class QTabWidget;
class MediaInfoDialog : public QVLCFrame
class MediaInfoDialog : public QVLCFrame, public Singleton<MediaInfoDialog>
{
Q_OBJECT;
public:
MediaInfoDialog( intf_thread_t *,
input_item_t * );
static MediaInfoDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance) instance = new MediaInfoDialog( p_intf, NULL );
return instance;
}
static void killInstance()
{
delete instance;
instance = NULL;
}
input_item_t * input = NULL );
void showTab( int );
#if 0
......@@ -57,7 +46,6 @@ public:
private:
virtual ~MediaInfoDialog();
static MediaInfoDialog *instance;
bool isMainInputInfo;
QTabWidget *infoTabW;
......@@ -77,6 +65,8 @@ private slots:
void saveMeta();
void updateButtons( int i_tab );
friend class Singleton<MediaInfoDialog>;
};
#endif
......@@ -41,8 +41,6 @@
#include <assert.h>
MessagesDialog *MessagesDialog::instance = NULL;
enum {
MsgEvent_Type = QEvent::User + MsgEventType + 1,
};
......
......@@ -25,6 +25,7 @@
#define QVLC_MESSAGES_DIALOG_H_ 1
#include "util/qvlcframe.hpp"
#include "util/singleton.hpp"
class QTabWidget;
class QPushButton;
......@@ -35,28 +36,13 @@ class QTextEdit;
class QTreeWidget;
class QTreeWidgetItem;
class MessagesDialog : public QVLCFrame
class MessagesDialog : public QVLCFrame, public Singleton<MessagesDialog>
{
Q_OBJECT;
public:
static MessagesDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance)
instance = new MessagesDialog( p_intf );
return instance;
}
static void killInstance()
{
delete instance;
instance = NULL;
}
private:
MessagesDialog( intf_thread_t * );
virtual ~MessagesDialog();
static MessagesDialog *instance;
QTabWidget *mainTab;
QSpinBox *verbosityBox;
QLabel *verbosityLabel;
......@@ -78,6 +64,8 @@ private:
void clear();
void updateTree();
void buildTree( QTreeWidgetItem *, vlc_object_t * );
friend class Singleton<MessagesDialog>;
};
#endif
......@@ -40,24 +40,9 @@
#include <assert.h>
OpenUrlDialog *OpenUrlDialog::instance = NULL;
OpenUrlDialog* OpenUrlDialog::getInstance( QWidget *parent,
intf_thread_t *p_intf,
bool bClipboard )
{
/* Creation */
if( !instance )
instance = new OpenUrlDialog( parent, p_intf, bClipboard );
else
instance->bClipboard = bClipboard;
return instance;
}
OpenUrlDialog::OpenUrlDialog( QWidget *parent,
intf_thread_t *_p_intf,
OpenUrlDialog::OpenUrlDialog( intf_thread_t *_p_intf,
bool _bClipboard ) :
QVLCDialog( parent, _p_intf ), bClipboard( _bClipboard )
QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf ), bClipboard( _bClipboard )
{
setWindowTitle( qtr( "Open URL" ) );
setWindowRole( "vlc-open-url" );
......
......@@ -30,21 +30,20 @@
#include <vlc_common.h>
#include "util/qvlcframe.hpp"
#include "util/singleton.hpp"
class ClickLineEdit;
class OpenUrlDialog : public QVLCDialog
class OpenUrlDialog : public QVLCDialog, public Singleton<OpenUrlDialog>
{
Q_OBJECT
private:
OpenUrlDialog( QWidget *, intf_thread_t *, bool bClipboard = true );
OpenUrlDialog( intf_thread_t *, bool bClipboard = true );
QString lastUrl;
bool bClipboard, bShouldEnqueue;
ClickLineEdit *edit;
static OpenUrlDialog *instance;
private slots:
void enqueue();
void play();
......@@ -52,16 +51,14 @@ private slots:
public:
virtual ~OpenUrlDialog() {}
static OpenUrlDialog* getInstance( QWidget *parent,
intf_thread_t *p_intf,
bool bClipboard = true );
QString url() const;
bool shouldEnqueue() const;
void showEvent( QShowEvent *ev );
public slots:
virtual void close() { play(); };
friend class Singleton<OpenUrlDialog>;
};
#endif
......@@ -33,8 +33,6 @@
#include <QUrl>
#include <QHBoxLayout>
PlaylistDialog *PlaylistDialog::instance = NULL;
PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf )
: QVLCMW( _p_intf )
{
......
......@@ -26,6 +26,7 @@
#include "util/qvlcframe.hpp"
#include "../components/playlist/playlist.hpp"
#include "util/singleton.hpp"
#include <QModelIndex>
......@@ -34,23 +35,12 @@ class PLSelector;
class PLPanel;
class QSettings;
class PlaylistDialog : public QVLCMW
class PlaylistDialog : public QVLCMW, public Singleton<PlaylistDialog>
{
Q_OBJECT;
private:
PlaylistWidget *playlistWidget;
public:
static PlaylistDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance) instance = new PlaylistDialog( p_intf );
return instance;
}
static void killInstance()
{
delete instance;
instance = NULL;
}
private:
PlaylistDialog( intf_thread_t * );
virtual ~PlaylistDialog();
......@@ -60,7 +50,7 @@ private:
void dragMoveEvent( QDragMoveEvent * );
void dragLeaveEvent( QDragLeaveEvent * );
static PlaylistDialog *instance;
friend class Singleton<PlaylistDialog>;
};
......
......@@ -38,8 +38,6 @@
#include <QLineEdit>
#include <QLabel>
PluginDialog *PluginDialog::instance = NULL;
PluginDialog::PluginDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
{
setWindowTitle( qtr( "Plugins and extensions" ) );
......
......@@ -25,6 +25,7 @@
#define QVLC_PLUGIN_DIALOG_H_ 1
#include "util/qvlcframe.hpp"
#include "util/singleton.hpp"
#include <QTreeWidget>
#include <QStringList>
......@@ -32,31 +33,21 @@ class QTreeWidget;
class QLineEdit;
class SearchLineEdit;
class PluginDialog : public QVLCFrame
class PluginDialog : public QVLCFrame, public Singleton<PluginDialog>
{
Q_OBJECT;
public:
static PluginDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance)
instance = new PluginDialog( p_intf );
return instance;
}
static void killInstance()
{
delete instance;
instance = NULL;
}
private:
PluginDialog( intf_thread_t * );
virtual ~PluginDialog();
static PluginDialog *instance;
void FillTree();
QTreeWidget *treePlugins;
SearchLineEdit *edit;
private slots:
void search( const QString& );
friend class Singleton<PluginDialog>;
};
class PluginTreeItem : public QTreeWidgetItem
......
......@@ -26,10 +26,8 @@
#include "podcast_configuration.hpp"
PodcastConfigDialog *PodcastConfigDialog::instance = NULL;
PodcastConfigDialog::PodcastConfigDialog( QWidget *parent, intf_thread_t *_p_intf)
: QVLCDialog( parent, _p_intf )
PodcastConfigDialog::PodcastConfigDialog( intf_thread_t *_p_intf)
: QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
{
ui.setupUi( this );
......
......@@ -26,28 +26,23 @@
#include "util/qvlcframe.hpp"
#include "ui/podcast_configuration.h"
#include "util/singleton.hpp"
class PodcastConfigDialog : public QVLCDialog
class PodcastConfigDialog : public QVLCDialog, public Singleton<PodcastConfigDialog>
{
Q_OBJECT;
public:
static PodcastConfigDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance )
instance = new PodcastConfigDialog( (QWidget *)p_intf->p_sys->p_mi,
p_intf );
return instance;
}
virtual ~PodcastConfigDialog();
private:
PodcastConfigDialog( QWidget *, intf_thread_t * );
static PodcastConfigDialog *instance;
PodcastConfigDialog( intf_thread_t * );
virtual ~PodcastConfigDialog();
Ui::PodcastConfiguration ui;
public slots:
void accept();
void add();
void remove();
friend class Singleton<PodcastConfigDialog>;
};
#endif
......@@ -55,9 +55,7 @@
#include <QFileDialog>
VLMDialog *VLMDialog::instance = NULL;
VLMDialog::VLMDialog( QWidget *parent, intf_thread_t *_p_intf ) : QVLCDialog( parent, _p_intf )
VLMDialog::VLMDialog( intf_thread_t *_p_intf ) : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
{
p_vlm = vlm_New( p_intf );
......
......@@ -35,6 +35,7 @@
#include "ui/vlm.h"
#include "util/qvlcframe.hpp"
#include "util/singleton.hpp"
#include <QDateTime>
enum{
......@@ -67,24 +68,19 @@ class VLMAWidget;
class VLMWrapper;
class VLMDialog : public QVLCDialog
class VLMDialog : public QVLCDialog, public Singleton<VLMDialog>
{
Q_OBJECT;
public:
static VLMDialog * getInstance( intf_thread_t *p_intf )
{
if( !instance)
instance = new VLMDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
return instance;
};
virtual ~VLMDialog();
void toggleVisible();
VLMWrapper *vlmWrapper;
vlm_t *p_vlm;
private:
VLMDialog( QWidget *, intf_thread_t * );
static VLMDialog *instance;
VLMDialog( intf_thread_t * );
virtual ~VLMDialog();
Ui::Vlm ui;
QList<VLMAWidget *> vlmItems;
......@@ -111,6 +107,8 @@ private slots:
void selectOutput();
bool exportVLMConf();
bool importVLMConf();
friend class Singleton<VLMDialog>;
};