Commit b5260216 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Move uncategorized settings to a private category

parent ac37b124
......@@ -78,12 +78,12 @@ MainWindow::MainWindow( QWidget *parent ) :
//VLC Instance:
LibVLCpp::Instance::getInstance();
//Creating the project manager first (so it can create all the project variables)
GUIProjectManager::getInstance();
//Preferences
initVlmcPreferences();
//Creating the project manager so it can create all the project variables
GUIProjectManager::getInstance();
// GUI
DockWidgetManager::getInstance( this )->setMainWindow( this );
createGlobalPreferences();
......@@ -128,6 +128,7 @@ MainWindow::MainWindow( QWidget *parent ) :
connect( Library::getInstance(), SIGNAL( clipRemoved( const QUuid& ) ),
clipRenderer, SLOT( clipUnloaded( const QUuid& ) ) );
//FIXME: Lazy init this
// Wizard
m_pWizard = new ProjectWizard( this );
m_pWizard->setModal( true );
......@@ -137,12 +138,10 @@ MainWindow::MainWindow( QWidget *parent ) :
if ( restoreSession() == true )
return ;
#endif
QSettings s;
// Restore the geometry
restoreGeometry( s.value( "MainWindowGeometry" ).toByteArray() );
restoreGeometry( VLMC_GET_BYTEARRAY( "private/MainWindowGeometry" ) );
// Restore the layout
restoreState( s.value( "MainWindowState" ).toByteArray() );
restoreState( VLMC_GET_BYTEARRAY( "private/MainWindowState" ) );
}
MainWindow::~MainWindow()
......@@ -156,9 +155,7 @@ MainWindow::~MainWindow()
void
MainWindow::showWizard()
{
QSettings s;
if ( s.value( "ShowWizardStartup", true ).toBool() )
if ( VLMC_GET_BOOL( "private/ShowWizardStartup" ) )
m_pWizard->show();
}
......@@ -322,18 +319,31 @@ MainWindow::initVlmcPreferences()
QT_TRANSLATE_NOOP( "PreferenceWidget", "Proxy Password" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Set Proxy Password, if any." ) );
// Setup private variables
VLMC_CREATE_PRIVATE_PREFERENCE_BOOL( "private/CleanQuit", true );
VLMC_CREATE_PRIVATE_PREFERENCE_STRING( "private/EmergencyBackup", "" );
VLMC_CREATE_PRIVATE_PREFERENCE_STRING( "private/ImportPreviouslySelectPath", QDir::homePath() );
VLMC_CREATE_PRIVATE_PREFERENCE_BYTEARRAY( "private/MainWindowGeometry", "" );
VLMC_CREATE_PRIVATE_PREFERENCE_BYTEARRAY( "private/MainWindowState", "" );
VLMC_CREATE_PRIVATE_PREFERENCE_STRING( "private/RecentsProjects", "" );
VLMC_CREATE_PRIVATE_PREFERENCE_BOOL( "private/ShowWizardStartup", true );
VLMC_CREATE_PRIVATE_PREFERENCE_STRING( "private/VlmcVersion", PROJECT_VERSION_MAJOR );
//Load saved preferences :
QSettings s;
if ( s.value( "VlmcVersion" ).toString() != PROJECT_VERSION_MAJOR )
s.clear();
else
loadVlmcPreferences( "private" );
if ( VLMC_GET_STRING( "private/VlmcVersion" ) == PROJECT_VERSION_MAJOR )
{
loadVlmcPreferences( "keyboard" );
loadVlmcPreferences( "general" );
loadVlmcPreferences( "youtube" );
loadVlmcPreferences( "network" );
}
s.setValue( "VlmcVersion", PROJECT_VERSION_MAJOR );
else
{
QSettings s;
s.clear();
}
SettingsManager::getInstance()->setValue( "private/VlmcVersion", PROJECT_VERSION_MAJOR, SettingsManager::Vlmc );
}
void
......@@ -343,8 +353,9 @@ MainWindow::loadVlmcPreferences( const QString &subPart )
s.beginGroup( subPart );
foreach ( QString key, s.allKeys() )
{
SettingsManager::getInstance()->setValue( subPart + "/" + key, s.value( key ),
SettingsManager::Vlmc );
QVariant value = s.value( key );
vlmcDebug() << "Loading" << key << "=>" << value;
SettingsManager::getInstance()->setValue( subPart + "/" + key, value, SettingsManager::Vlmc );
}
}
......@@ -771,13 +782,12 @@ MainWindow::saveSettings()
clearTemporaryFiles();
if ( pm->askForSaveIfModified() )
{
QSettings s;
SettingsManager* sm = SettingsManager::getInstance();
// Save the current geometry
s.setValue( "MainWindowGeometry", saveGeometry() );
sm->setValue( "private/MainWindowGeometry", saveGeometry(), SettingsManager::Vlmc );
// Save the current layout
s.setValue( "MainWindowState", saveState() );
s.setValue( "CleanQuit", true );
s.sync();
sm->setValue( "private/MainWindowState", saveState(), SettingsManager::Vlmc );
sm->setValue( "private/CleanQuit", true, SettingsManager::Vlmc );
return true;
}
return false;
......@@ -834,30 +844,22 @@ MainWindow::on_actionCrash_triggered()
bool
MainWindow::restoreSession()
{
QSettings s;
bool fileCreated = false;
bool ret = false;
bool cleanQuit = VLMC_GET_BOOL( "private/CleanQuit" );
bool ret = false;
fileCreated = s.contains( "VlmcVersion" );
if ( fileCreated == true )
if ( cleanQuit == false )
{
bool cleanQuit = s.value( "CleanQuit", true ).toBool();
if ( cleanQuit == false )
QMessageBox::StandardButton res = QMessageBox::question( this, tr( "Crash recovery" ), tr( "VLMC didn't closed nicely. Do you want to recover your project?" ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
if ( res == QMessageBox::Yes )
{
QMessageBox::StandardButton res = QMessageBox::question( this, tr( "Crash recovery" ), tr( "VLMC didn't closed nicely. Do you want to recover your project?" ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
if ( res == QMessageBox::Yes )
{
if ( GUIProjectManager::getInstance()->loadEmergencyBackup() == true )
ret = true;
else
QMessageBox::warning( this, tr( "Can't restore project" ), tr( "VLMC didn't manage to restore your project. We apology for the inconvenience" ) );
}
if ( GUIProjectManager::getInstance()->loadEmergencyBackup() == true )
ret = true;
else
QMessageBox::warning( this, tr( "Can't restore project" ), tr( "VLMC didn't manage to restore your project. We apology for the inconvenience" ) );
}
}
s.setValue( "CleanQuit", false );
s.sync();
SettingsManager::getInstance()->setValue( "private/CleanQuit", true, SettingsManager::Vlmc );
return ret;
}
......
......@@ -34,6 +34,7 @@
#include "MediaListView.h"
#include "MetaDataManager.h"
#include "PreviewWidget.h"
#include "SettingsManager.h"
#include "TagWidget.h"
#include "Transcoder.h"
#include "VlmcDebug.h"
......@@ -288,19 +289,17 @@ ImportController::collapseAllButCurrentPath()
void
ImportController::saveCurrentPath()
{
QSettings s;
s.setValue( "ImportPreviouslySelectPath", m_currentlyWatchedDir );
s.sync();
SettingsManager::getInstance()->setValue( "private/ImportPreviouslySelectPath",
m_currentlyWatchedDir, SettingsManager::Vlmc );
}
void
ImportController::restoreCurrentPath()
{
QSettings s;
QVariant path = s.value( "ImportPreviouslySelectPath", QDir::homePath() );
if ( QFile::exists( path.toString() ) == false )
QString path = VLMC_GET_STRING( "private/ImportPreviouslySelectPath" );
if ( QFile::exists( path ) == false )
path = QDir::homePath();
QFileInfo info = path.toString();
QFileInfo info = path;
m_currentlyWatchedDir = info.absoluteFilePath();
}
......
......@@ -35,6 +35,7 @@ TrackControls::TrackControls( GraphicsTrack* track, QWidget *parent ) :
m_ui( new Ui::TrackControls ),
m_track( track )
{
//FIXME: This type of things should be in the project settings
QSettings s( QSettings::UserScope, qApp->organizationName(), "timeline" );
if ( track->mediaType() == Workflow::VideoTrack &&
s.contains( "video" + QString::number( track->trackNumber() ) ) )
......
......@@ -217,6 +217,5 @@ WelcomePage::setProjectPath( const QString& path )
void
WelcomePage::hideWizardAtStartup( bool hidden )
{
QSettings s;
s.setValue( "ShowWizardStartup", !hidden );
SettingsManager::getInstance()->setValue( "private/ShowWizardStartup", !hidden, SettingsManager::Vlmc );
}
......@@ -35,7 +35,6 @@
#include <QDir>
#include <QMessageBox>
#include <QSettings>
#include <QXmlStreamWriter>
#include <errno.h>
#include <signal.h>
......@@ -46,8 +45,7 @@ const QString ProjectManager::backupSuffix = "~";
ProjectManager::ProjectManager() : m_projectFile( NULL ), m_needSave( false )
{
QSettings s;
m_recentsProjects = s.value( "RecentsProjects" ).toStringList();
m_recentsProjects = VLMC_GET_STRINGLIST( "private/RecentsProjects" );
//If the variable was empty, it will return a list with one empty string in it.
m_recentsProjects.removeAll( "" );
......@@ -176,8 +174,7 @@ ProjectManager::removeProject( const QString& project )
// Remove all occurence of fileName
m_recentsProjects.removeAll( project );
QSettings s;
s.setValue( "RecentsProjects", m_recentsProjects );
SettingsManager::getInstance()->setValue( "private/RecentsProjects", m_recentsProjects, SettingsManager::Vlmc );
}
void
......@@ -215,9 +212,7 @@ ProjectManager::emergencyBackup()
else
name = createAutoSaveOutputFileName( QDir::currentPath() + "/unsavedproject" );
__saveProject( name );
QSettings s;
s.setValue( "EmergencyBackup", name );
s.sync();
SettingsManager::getInstance()->setValue( "private/EmergencyBackup", name, SettingsManager::Vlmc );
}
bool
......@@ -288,8 +283,7 @@ ProjectManager::saveAs( const QString &outputFileName )
bool
ProjectManager::loadEmergencyBackup()
{
QSettings s;
QString lastProject = s.value( "EmergencyBackup" ).toString();
QString lastProject = VLMC_GET_STRING( "private/EmergencyBackup" );
if ( QFile::exists( lastProject ) == true )
{
loadProject( lastProject );
......
......@@ -46,6 +46,7 @@ class SettingValue : public QObject
Language,
KeyboardShortcut,
Path,
ByteArray, // For now this is only for private variables, and is not expected to be used at any time
//For effect engine settings:
Color,
Position
......
......@@ -38,11 +38,13 @@ class QDomElement;
//Var helpers :
#define VLMC_GET_STRING( key ) SettingsManager::getInstance()->value( key )->get().toString()
#define VLMC_GET_INT( key ) SettingsManager::getInstance()->value( key )->get().toInt()
#define VLMC_GET_UINT( key ) SettingsManager::getInstance()->value( key )->get().toUInt()
#define VLMC_GET_DOUBLE( key ) SettingsManager::getInstance()->value( key )->get().toDouble()
#define VLMC_GET_BOOL( key ) SettingsManager::getInstance()->value( key )->get().toBool()
#define VLMC_GET_STRING( key ) SettingsManager::getInstance()->value( key, SettingsManager::Vlmc )->get().toString()
#define VLMC_GET_INT( key ) SettingsManager::getInstance()->value( key, SettingsManager::Vlmc )->get().toInt()
#define VLMC_GET_UINT( key ) SettingsManager::getInstance()->value( key, SettingsManager::Vlmc )->get().toUInt()
#define VLMC_GET_DOUBLE( key ) SettingsManager::getInstance()->value( key, SettingsManager::Vlmc)->get().toDouble()
#define VLMC_GET_BOOL( key ) SettingsManager::getInstance()->value( key, SettingsManager::Vlmc)->get().toBool()
#define VLMC_GET_STRINGLIST( key ) SettingsManager::getInstance()->value( key, SettingsManager::Vlmc )->get().toStringList()
#define VLMC_GET_BYTEARRAY( key ) SettingsManager::getInstance()->value( key, SettingsManager::Vlmc )->get().toByteArray()
#define VLMC_PROJECT_GET_STRING( key ) SettingsManager::getInstance()->value( key, SettingsManager::Project )->get().toString()
#define VLMC_PROJECT_GET_INT( key ) SettingsManager::getInstance()->value( key, SettingsManager::Project )->get().toInt()
......@@ -92,10 +94,15 @@ SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \
VLMC_CREATE_PREFERENCE( SettingValue::String, key, defaultValue, "", "", SettingValue::Private )
#define VLMC_CREATE_PRIVATE_PREFERENCE_INT( key, defaultValue ) \
VLMC_CREATE_PREFERENCE( SettingValue::Int, key, defaultValue, "", "", SettingValue::Private )
#define VLMC_CREATE_PRIVATE_PROJECT_STRING( key, defaultValue ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::String, key, defaultValue, "", "", SettingValue::Private )
#define VLMC_CREATE_PRIVATE_PREFERENCE_BOOL( key, defaultValue ) \
VLMC_CREATE_PREFERENCE( SettingValue::Bool, key, defaultValue, "", "", SettingValue::Private )
#define VLMC_CREATE_PRIVATE_PREFERENCE_BYTEARRAY( key, defaultValue ) \
VLMC_CREATE_PREFERENCE( SettingValue::ByteArray, key, defaultValue, "", "", SettingValue::Private )
#define VLMC_CREATE_PREFERENCE_PASSWORD( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::String, key, defaultValue, name, desc, SettingValue::Password )
#define VLMC_CREATE_PRIVATE_PROJECT_STRING( key, defaultValue ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::String, key, defaultValue, "", "", SettingValue::Private )
class SettingsManager : public QObject, public Singleton<SettingsManager>
......
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