Commit 47392467 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Stop allocating QSettings all the time everywhere.

parent 8462c96d
......@@ -44,7 +44,6 @@
#include <QDirModel>
#include <QScrollArea>
#include <QUrl>
#include <QSettings>
#define I_DEVICE_TOOLTIP "Select the device or the VIDEO_TS directory"
......@@ -78,9 +77,8 @@ FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
dialogBox->setFileMode( QFileDialog::ExistingFiles );
dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
#if HAS_QT43
QSettings settings( "vlc", "vlc-qt-interface" );
dialogBox->restoreState(
settings.value( "file-dialog-state" ).toByteArray() );
getSettings()->value( "file-dialog-state" ).toByteArray() );
#endif
/* We don't want to see a grip in the middle of the window, do we? */
......@@ -145,8 +143,7 @@ FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
FileOpenPanel::~FileOpenPanel()
{
#if HAS_QT43
QSettings settings( "vlc", "vlc-qt-interface" );
settings.setValue( "file-dialog-state", dialogBox->saveState() );
getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
#endif
}
......
......@@ -43,7 +43,6 @@
**********************************************************************/
PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i,
QSettings *settings,
QWidget *_parent )
: p_intf ( _p_i ), parent( _parent )
{
......@@ -122,8 +121,8 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i,
/* In case we want to keep the splitter informations */
// components shall never write there setting to a fixed location, may infer
// with other uses of the same component...
// settings->beginGroup( "playlist" );
restoreState( settings->value("splitterSizes").toByteArray());
// getSettings()->beginGroup( "playlist" );
restoreState( getSettings()->value("splitterSizes").toByteArray());
}
void PlaylistWidget::setArt( QString url )
......@@ -143,8 +142,8 @@ QSize PlaylistWidget::sizeHint() const
PlaylistWidget::~PlaylistWidget()
{}
void PlaylistWidget::savingSettings( QSettings *settings )
void PlaylistWidget::savingSettings()
{
settings->setValue( "splitterSizes", saveState() );
getSettings()->setValue( "splitterSizes", saveState() );
}
......@@ -40,16 +40,15 @@
class PLSelector;
class PLPanel;
class QPushButton;
class QSettings;
class PlaylistWidget : public QSplitter
{
Q_OBJECT;
public:
PlaylistWidget( intf_thread_t *_p_i, QSettings *settings, QWidget *parent ) ;
PlaylistWidget( intf_thread_t *_p_i, QWidget *parent ) ;
virtual ~PlaylistWidget();
QSize sizeHint() const;
void savingSettings( QSettings *settings );
void savingSettings();
private:
PLSelector *selector;
PLPanel *rightPanel;
......
......@@ -48,7 +48,7 @@
*/
void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m, QSettings *settings )
{
parentItem = parent; /* Can be NULL, but only for the rootItem */
i_id = _i_id; /* Playlist item specific id */
......@@ -68,8 +68,7 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
}
else
{
QSettings settings( "vlc", "vlc-qt-interface" );
i_showflags = settings.value( "qt-pl-showflags", 39 ).toInt();
i_showflags = settings->value( "qt-pl-showflags", 39 ).toInt();
if( i_showflags < 1)
i_showflags = 39; /* reasonable default to show something; */
else if ( i_showflags >= COLUMN_END )
......@@ -93,12 +92,17 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
*/
PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
{
init( _i_id, _i_input_id, parent, m );
init( _i_id, _i_input_id, parent, m, NULL );
}
PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
{
init( p_item->i_id, p_item->p_input->i_id, parent, m );
init( p_item->i_id, p_item->p_input->i_id, parent, m, NULL );
}
PLItem::PLItem( playlist_item_t * p_item, QSettings *settings, PLModel *m )
{
init( p_item->i_id, p_item->p_input->i_id, NULL, m, settings );
}
PLItem::~PLItem()
......
......@@ -36,6 +36,7 @@
#include <QString>
#include <QList>
class QSettings;
class PLModel;
class PLItem
......@@ -44,6 +45,7 @@ class PLItem
public:
PLItem( int, int, PLItem *parent , PLModel * );
PLItem( playlist_item_t *, PLItem *parent, PLModel * );
PLItem( playlist_item_t *, QSettings *, PLModel * );
~PLItem();
int row() const;
......@@ -75,7 +77,7 @@ protected:
int i_showflags;
private:
void init( int, int, PLItem *, PLModel * );
void init( int, int, PLItem *, PLModel *, QSettings * );
void updateColumnHeaders();
PLItem *parentItem;
PLModel *model;
......
......@@ -98,8 +98,7 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
PLModel::~PLModel()
{
QSettings settings( "vlc", "vlc-qt-interface" );
settings.setValue( "qt-pl-showflags", rootItem->i_showflags );
getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
delCallbacks();
delete rootItem;
}
......@@ -591,7 +590,7 @@ void PLModel::rebuild( playlist_item_t *p_root )
if( p_root )
{
delete rootItem;
rootItem = new PLItem( p_root, NULL, this );
rootItem = new PLItem( p_root, getSettings(), this );
}
assert( rootItem );
/* Recreate from root */
......
......@@ -50,26 +50,24 @@ PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf )
QHBoxLayout *l = new QHBoxLayout( centralWidget() );
settings = new QSettings( "vlc", "vlc-qt-interface" );
settings->beginGroup("playlistdialog");
getSettings()->beginGroup("playlistdialog");
playlistWidget = new PlaylistWidget( p_intf, settings, this );
playlistWidget = new PlaylistWidget( p_intf, this );
l->addWidget( playlistWidget );
readSettings( settings, QSize( 600,700 ) );
readSettings( getSettings(), QSize( 600,700 ) );
settings->endGroup();
getSettings()->endGroup();
}
PlaylistDialog::~PlaylistDialog()
{
settings->beginGroup("playlistdialog");
getSettings()->beginGroup("playlistdialog");
writeSettings(settings);
playlistWidget->savingSettings(settings);
writeSettings( getSettings() );
playlistWidget->savingSettings();
settings->endGroup();
delete settings;
getSettings()->endGroup();
}
void PlaylistDialog::dropEvent( QDropEvent *event )
......
......@@ -39,7 +39,6 @@ class PlaylistDialog : public QVLCMW
Q_OBJECT;
private:
PlaylistWidget *playlistWidget;
QSettings *settings;
public:
static PlaylistDialog * getInstance( intf_thread_t *p_intf )
......
......@@ -110,7 +110,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
/* Set the other interface settings */
settings = new QSettings( "vlc", "vlc-qt-interface" );
settings = getSettings();
settings->beginGroup( "MainWindow" );
//TODO: I don't like that code
......@@ -224,7 +224,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
CONNECT( this, askUpdate(), this, doComponentsUpdate() );
/* Size and placement of interface */
QVLCTools::restoreWidgetPosition(settings,this,QSize(350,60));
QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
/* Playlist */
......@@ -250,7 +250,7 @@ MainInterface::~MainInterface()
msg_Dbg( p_intf, "Destroying the main interface" );
if( playlistWidget )
playlistWidget->savingSettings( settings );
playlistWidget->savingSettings();
settings->beginGroup( "MainWindow" );
......@@ -266,7 +266,6 @@ MainInterface::~MainInterface()
settings->setValue( "backgroundSize", bgWidget->size() );
settings->endGroup();
delete settings;
var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
......
......@@ -244,6 +244,7 @@ static int Open( vlc_object_t *p_this )
p_intf->p_sys->p_playlist = pl_Yield( p_intf );
/* Listen to the messages */
p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
/* one settings to rule them all */
var_Create( p_this, "window_widget", VLC_VAR_ADDRESS );
return VLC_SUCCESS;
......@@ -323,6 +324,7 @@ static void Init( intf_thread_t *p_intf )
QApplication *app = new QApplication( argc, argv , true );
p_intf->p_sys->p_app = app;
p_intf->p_sys->mainSettings = new QSettings( "vlc", "vlc-qt-interface" );
/* Icon setting
FIXME: use a bigger icon ? */
if( QDate::currentDate().dayOfYear() >= 354 )
......@@ -390,13 +392,12 @@ static void Init( intf_thread_t *p_intf )
if( config_GetInt( p_intf, "qt-updates-notif" ) )
{
int interval = config_GetInt( p_intf, "qt-updates-days" );
QSettings settings( "vlc", "vlc-qt-interface" );
if( QDate::currentDate() >
settings.value( "updatedate" ).toDate().addDays( interval ) )
getSettings()->value( "updatedate" ).toDate().addDays( interval ) )
{
/* The constructor of the update Dialog will do the 1st request */
UpdateDialog::getInstance( p_intf );
settings.setValue( "updatedate", QDate::currentDate() );
getSettings()->setValue( "updatedate", QDate::currentDate() );
}
}
#endif
......
......@@ -46,12 +46,15 @@ class QMenu;
class MainInterface;
class DialogsProvider;
class VideoWidget;
class QSettings;
struct intf_sys_t
{
QApplication *p_app;
MainInterface *p_mi;
QSettings *mainSettings;
bool b_isDialogProvider;
playlist_t *p_playlist;
......@@ -106,6 +109,8 @@ struct intf_sys_t
#define setLayoutMargins( a, b, c, d, e) setMargin( e )
#endif
#define getSettings() p_intf->p_sys->mainSettings
enum {
DialogEventType = 0,
IMEventType = 100,
......
......@@ -29,11 +29,11 @@
#include <QSpacerItem>
#include <QHBoxLayout>
#include <QApplication>
#include <QSettings>
#include <QMainWindow>
#include <QPushButton>
#include <QKeyEvent>
#include <QDesktopWidget>
#include <QSettings>
#include "qt4.hpp"
#include <vlc_common.h>
......@@ -48,17 +48,17 @@ class QVLCTools
window is docked into an other - don't all this function
or it may write garbage to position info!
*/
static void saveWidgetPosition(QSettings *settings, QWidget *widget)
static void saveWidgetPosition( QSettings *settings, QWidget *widget)
{
settings->setValue("geometry", widget->saveGeometry());
}
static void saveWidgetPosition(QString configName, QWidget *widget)
static void saveWidgetPosition( intf_thread_t *p_intf,
QString configName,
QWidget *widget)
{
QSettings *settings = new QSettings("vlc", "vlc-qt-interface");
settings->beginGroup( configName );
QVLCTools::saveWidgetPosition(settings, widget);
settings->endGroup();
delete settings;
getSettings()->beginGroup( configName );
QVLCTools::saveWidgetPosition(getSettings(), widget);
getSettings()->endGroup();
}
......@@ -84,19 +84,18 @@ class QVLCTools
return false;
}
static bool restoreWidgetPosition(QString configName,
static bool restoreWidgetPosition( intf_thread_t *p_intf,
QString configName,
QWidget *widget,
QSize defSize = QSize( 0, 0 ),
QPoint defPos = QPoint( 0, 0 ) )
{
QSettings *settings = new QSettings( "vlc", "vlc-qt-interface" );
settings->beginGroup( configName );
bool defaultUsed = QVLCTools::restoreWidgetPosition(settings,
getSettings()->beginGroup( configName );
bool defaultUsed = QVLCTools::restoreWidgetPosition( getSettings(),
widget,
defSize,
defPos);
settings->endGroup();
delete settings;
getSettings()->endGroup();
return defaultUsed;
}
......@@ -138,12 +137,12 @@ protected:
QSize defSize = QSize( 0, 0 ),
QPoint defPos = QPoint( 0, 0 ) )
{
QVLCTools::restoreWidgetPosition(name, this, defSize, defPos);
QVLCTools::restoreWidgetPosition(p_intf, name, this, defSize, defPos);
}
void writeSettings( QString name )
{
QVLCTools::saveWidgetPosition(name, this);
QVLCTools::saveWidgetPosition( p_intf, name, this);
}
virtual void cancel()
......@@ -225,14 +224,13 @@ protected:
void readSettings( QString name, QSize defSize )
{
QVLCTools::restoreWidgetPosition(name, this, defSize);
QVLCTools::restoreWidgetPosition( p_intf, name, this, defSize);
}
void readSettings( QString name )
{
QVLCTools::restoreWidgetPosition(name, this);
QVLCTools::restoreWidgetPosition( p_intf, name, this);
}
void readSettings( QSettings *settings )
{
QVLCTools::restoreWidgetPosition(settings, this);
......@@ -245,14 +243,12 @@ protected:
void writeSettings(QString name )
{
QVLCTools::saveWidgetPosition(name, this);
QVLCTools::saveWidgetPosition( p_intf, name, this);
}
void writeSettings(QSettings *settings )
{
QVLCTools::saveWidgetPosition(settings, this);
}
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment