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

Extract recent projects list out of ProjectManager

parent f147dbc0
......@@ -36,6 +36,7 @@ SET(VLMC_SRCS
Project/ProjectManager.cpp
Project/Workspace.cpp
Project/WorkspaceWorker.cpp
Project/RecentProjects.cpp
Renderer/ClipRenderer.cpp
Renderer/GenericRenderer.cpp
Renderer/WorkflowFileRenderer.cpp
......
......@@ -65,6 +65,7 @@
/* Settings / Preferences */
#include "project/GuiProjectManager.h"
#include "Project/RecentProjects.h"
#include "wizard/ProjectWizard.h"
#include "Settings/Settings.h"
#include "LanguageHelper.h"
......@@ -78,9 +79,7 @@ MainWindow::MainWindow( Backend::IBackend* backend, QWidget *parent )
{
m_ui.setupUi( this );
//We only install message handler here cause it uses configuration.
Core::getInstance()->logger()->setup();
//Preferences
initVlmcPreferences();
//All preferences have been created: restore them:
......@@ -324,8 +323,6 @@ MainWindow::initVlmcPreferences()
VLMC_CREATE_PRIVATE_PREFERENCE_STRING( "private/ImportPreviouslySelectPath", QDir::homePath() );
VLMC_CREATE_PRIVATE_PREFERENCE_BYTEARRAY( "private/MainWindowGeometry", "" );
VLMC_CREATE_PRIVATE_PREFERENCE_BYTEARRAY( "private/MainWindowState", "" );
Core::getInstance()->settings()->createVar( SettingValue::String, "private/RecentsProjects", "",
"", "", SettingValue::Private );
Core::getInstance()->settings()->createVar( SettingValue::Bool, "vlmc/AutomaticBackup", false,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save" ),
......
......@@ -22,7 +22,7 @@
#include "WelcomePage.h"
#include "project/GuiProjectManager.h"
#include "Project/RecentProjects.h"
#include "Settings/Settings.h"
#include <QFileDialog>
......@@ -118,12 +118,11 @@ void
WelcomePage::loadRecentsProjects()
{
m_ui.projectsListWidget->clear();
ProjectManager* pm = Project::getInstance()->projectManager();
const ProjectManager::RecentProjectsList& recents = pm->recentsProjects();
const RecentProjects::List& recents = Core::getInstance()->recentProjects()->list();
for ( int i = 0; i < recents.count(); ++i )
{
ProjectManager::RecentProject project = recents.at( i );
RecentProjects::Project project = recents.at( i );
QListWidgetItem* item = new QListWidgetItem( project.name );
item->setData( FilePath, project.filePath );
m_ui.projectsListWidget->addItem( item );
......@@ -171,11 +170,11 @@ WelcomePage::removeProject()
if ( selected.isEmpty() )
return;
const QString project = selected.at( 0 )->data( FilePath ).toString();
if ( project.isEmpty() )
const QString projectPath = selected.at( 0 )->data( FilePath ).toString();
if ( projectPath.isEmpty() )
return;
Project::getInstance()->projectManager()->removeProject( project );
Core::getInstance()->recentProjects()->remove( projectPath );
loadRecentsProjects(); // Reload recent projects
}
......
......@@ -35,6 +35,7 @@
#include <EffectsEngine/EffectsEngine.h>
#include <Settings/Settings.h>
#include <Tools/VlmcLogger.h>
#include "Project/RecentProjects.h"
Core::Core()
{
......@@ -50,6 +51,7 @@ Core::Core()
QString configPath = configDir + QDir::separator() + qApp->organizationName()
+ QDir::separator() + qApp->applicationName() + ".conf";
m_settings = new Settings( configPath );
m_recentProjects = new RecentProjects( m_settings );
}
Core::~Core()
......@@ -78,6 +80,12 @@ Core::logger()
return m_logger;
}
RecentProjects*
Core::recentProjects()
{
return m_recentProjects;
}
Settings*
Core::settings()
{
......
......@@ -25,6 +25,7 @@
class EffectsEngine;
class NotificationZone;
class RecentProjects;
class Settings;
class VlmcLogger;
......@@ -42,6 +43,7 @@ class Core : public Singleton<Core>
EffectsEngine* effectsEngine();
Settings* settings();
VlmcLogger* logger();
RecentProjects* recentProjects();
private:
Core();
......@@ -50,6 +52,7 @@ class Core : public Singleton<Core>
EffectsEngine* m_effectsEngine;
Settings* m_settings;
VlmcLogger* m_logger;
RecentProjects* m_recentProjects;
friend class Singleton<Core>;
};
......
......@@ -42,7 +42,6 @@
#include "Renderer/WorkflowRenderer.h"
#include "Project/Workspace.h"
#define SETTINGS_RECENTS "private/RecentsProjects"
#define SETTINGS_BACKUP "private/EmergencyBackup"
const QString ProjectManager::unNamedProject = ProjectManager::tr( "Untitled Project" );
......@@ -103,8 +102,6 @@ ProjectManager::ProjectManager( Settings* projectSettings, Settings* vlmcSetting
Qt::QueuedConnection );
projectSettings->watchValue( "vlmc/ProjectName", this, SLOT(projectNameChanged(QVariant) ) );
loadRecentProjects();
//We have to wait for the library to be loaded before loading the workflow
//FIXME
//connect( Project::getInstance()->library(), SIGNAL( projectLoaded() ), this, SLOT( loadWorkflow() ) );
......@@ -122,13 +119,6 @@ ProjectManager::setProjectManagerUi( IProjectManagerUiCb *projectManagerUi )
m_projectManagerUi = projectManagerUi;
}
const ProjectManager::RecentProjectsList&
ProjectManager::recentsProjects() const
{
return m_recentsProjects;
}
void
ProjectManager::loadWorkflow()
{
......@@ -138,24 +128,15 @@ ProjectManager::loadWorkflow()
Project::getInstance()->workflow()->loadProject( root );
loadTimeline( root );
if ( m_projectFile != NULL )
{
appendToRecentProject( projectName(), m_projectFile->fileName() );
savedState = true;
}
else
savedState = false;
emit projectUpdated( projectName(), savedState );
emit projectLoaded( projectName(), m_projectFile->fileName() );
delete m_domDocument;
}
void
ProjectManager::removeProject( const QString& projectPath )
{
removeFromRecentProjects( projectPath );
Core::getInstance()->settings()->setValue( SETTINGS_RECENTS, flattenProjectList() );
}
void
ProjectManager::saveProject( const QString& fileName )
{
......@@ -219,50 +200,6 @@ ProjectManager::createAutoSaveOutputFileName( const QString& baseName ) const
return baseName + ProjectManager::backupSuffix;
}
void
ProjectManager::removeFromRecentProjects(const QString &projectPath)
{
RecentProjectsList::iterator it = m_recentsProjects.begin();
RecentProjectsList::iterator ite = m_recentsProjects.end();
while ( it != ite )
{
if ( (*it).filePath == projectPath )
it = m_recentsProjects.erase( it );
else
++it;
}
}
QString
ProjectManager::flattenProjectList() const
{
if ( m_recentsProjects.count() == 0 )
return QString();
QString res;
foreach (RecentProject p, m_recentsProjects)
{
res += p.name + '#' + p.filePath + '#';
}
res.chop(1);
return res;
}
void
ProjectManager::appendToRecentProject( const QString& projectName, const QString& projectPath )
{
// Append the item to the recents list
removeFromRecentProjects( projectName );
RecentProject project;
project.name = projectName;
project.filePath = projectPath;
m_recentsProjects.prepend( project );
while ( m_recentsProjects.count() > 15 )
m_recentsProjects.removeLast();
Core::getInstance()->settings()->setValue( SETTINGS_RECENTS, flattenProjectList() );
Core::getInstance()->settings()->save();
}
QString
ProjectManager::projectName() const
{
......@@ -367,7 +304,7 @@ ProjectManager::newProject( const QString &projectName, const QString &workspace
//Current project file has already been delete/nulled by ProjectManager::closeProject()
m_projectFile = new QFile( workspacePath + '/' + "project.vlmc" );
save();
appendToRecentProject( projectName, m_projectFile->fileName() );
emit projectLoaded( projectName, m_projectFile->fileName() );
}
void
......@@ -453,32 +390,6 @@ ProjectManager::autoSaveRequired()
ProjectManager::saveProject( createAutoSaveOutputFileName( m_projectFile->fileName() ) );
}
void
ProjectManager::loadRecentProjects()
{
QString recentProjects = m_vlmcSettings->value( SETTINGS_RECENTS )->get().toString();
const QStringList recentProjectsList = recentProjects.split( '#' );
if ( recentProjectsList.count() == 0 )
return ;
QStringList::const_iterator it = recentProjectsList.begin();
QStringList::const_iterator ite = recentProjectsList.end();
m_recentsProjects.clear();
while ( it != ite )
{
RecentProject project;
project.name = *it;
++it;
if ( it == ite )
{
vlmcWarning() << "Invalid flattened recent projects list.";
return ;
}
project.filePath = *it;
++it;
m_recentsProjects.append( project );
}
}
bool
ProjectManager::closeProject()
{
......@@ -504,5 +415,4 @@ ProjectManager::closeProject()
return true;
}
#undef SETTINGS_RECENTS
#undef SETTINGS_BACKUP
......@@ -86,20 +86,14 @@ public:
static const QString unNamedProject;
static const QString unSavedProject;
static const QString backupSuffix;
struct RecentProject
{
QString name;
QString filePath;
};
typedef QList<RecentProject> RecentProjectsList;
ProjectManager( Settings *projectSettings , Settings *vlmcSettings );
~ProjectManager();
void setProjectManagerUi( IProjectManagerUiCb* projectManagerUi );
void removeProject( const QString& projectPath );
const RecentProjectsList& recentsProjects() const;
bool closeProject();
void save();
......@@ -126,7 +120,6 @@ private:
*/
void saveTimeline(QXmlStreamWriter& project);
static bool isBackupFile( const QString& projectFile );
void appendToRecentProject(const QString& projectName , const QString &projectPath);
/**
* \brief Get the project name
*
......@@ -140,16 +133,12 @@ private:
void failedToLoad( const QString& reason ) const;
void loadTimeline( const QDomElement& ){}
QString createAutoSaveOutputFileName( const QString& baseName ) const;
void removeFromRecentProjects( const QString& projectPath );
QString flattenProjectList() const;
void loadRecentProjects();
protected:
QFile* m_projectFile;
// We list recent projects as a list of [ProjectName,ProjectPath].
// Since this is handled as a QVariant, arrays don't work.
RecentProjectsList m_recentsProjects;
QString m_projectName;
QString m_projectDescription;
QDomDocument* m_domDocument;
......@@ -182,6 +171,14 @@ signals:
*/
void projectSaved();
void projectClosed();
/**
* @brief projectLoaded Emited when a project is loaded (which also include a project
* being created)
* @param projectName The project name
* @param projectPath The path to the project file
*/
void projectLoaded( const QString& projectName, const QString& projectPath );
};
#endif // PROJECTMANAGER_H
/*****************************************************************************
* RecentProjects: Holds a list of recent projects by monitoring project events
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "RecentProjects.h"
#include "Project/ProjectManager.h"
#include "Settings/Settings.h"
#include "Tools/VlmcDebug.h"
RecentProjects::RecentProjects( Settings* vlmcSettings, QObject *parent )
: QObject(parent)
, m_settings( vlmcSettings )
, m_projectManager( NULL )
{
vlmcSettings->createVar( SettingValue::String, "private/RecentsProjects", "",
"", "", SettingValue::Private );
vlmcSettings->watchValue( "private/RecentsProjects",
this, SLOT( loadRecentProjects( QVariant ) ) );
}
void
RecentProjects::setProject(ProjectManager* projectManager)
{
if ( m_projectManager != NULL )
disconnect( m_projectManager, SIGNAL( projectLoaded( QString, QString ) ) );
m_projectManager = projectManager;
connect( projectManager, SIGNAL( projectLoaded( QString, QString ) ),
this, SLOT( projectLoaded( QString, QString ) ) );
}
void
RecentProjects::projectLoaded(const QString& projectName, const QString& projectFile)
{
removeFromRecentProjects( projectName );
Project project;
project.name = projectName;
project.filePath = projectFile;
m_recentsProjects.prepend( project );
while ( m_recentsProjects.count() > 15 )
m_recentsProjects.removeLast();
Core::getInstance()->settings()->setValue( "private/RecentsProjects", flattenProjectList() );
}
const RecentProjects::List&
RecentProjects::list() const
{
return m_recentsProjects;
}
QString
RecentProjects::flattenProjectList() const
{
if ( m_recentsProjects.count() == 0 )
return QString();
QString res;
foreach ( Project p, m_recentsProjects )
{
res += p.name + '#' + p.filePath + '#';
}
res.chop(1);
return res;
}
void
RecentProjects::removeFromRecentProjects( const QString &projectPath )
{
List::iterator it = m_recentsProjects.begin();
List::iterator ite = m_recentsProjects.end();
while ( it != ite )
{
if ( (*it).filePath == projectPath )
it = m_recentsProjects.erase( it );
else
++it;
}
}
void
RecentProjects::remove( const QString& projectPath )
{
removeFromRecentProjects( projectPath );
Core::getInstance()->settings()->setValue( "private/RecentsProjects", flattenProjectList() );
}
void
RecentProjects::loadRecentProjects( const QVariant& recentProjects )
{
// Only watch initial loading, we are now taking ownership of "private/RecentsProjects settings"
disconnect( this, SLOT( loadRecentProjects( QVariant ) ) );
const QStringList recentProjectsList = recentProjects.toString().split( '#' );
if ( recentProjectsList.count() == 0 )
return ;
QStringList::const_iterator it = recentProjectsList.begin();
QStringList::const_iterator ite = recentProjectsList.end();
while ( it != ite )
{
Project project;
project.name = *it;
++it;
if ( it == ite )
{
vlmcWarning() << "Invalid flattened recent projects list.";
return ;
}
project.filePath = *it;
++it;
m_recentsProjects.append( project );
}
}
/*****************************************************************************
* RecentProjects: Holds a list of recent projects by monitoring project events
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef RECENTPROJECTS_H
#define RECENTPROJECTS_H
#include <QObject>
class ProjectManager;
class Settings;
class RecentProjects : public QObject
{
Q_OBJECT
public:
struct Project
{
QString name;
QString filePath;
};
typedef QList<Project> List;
explicit RecentProjects(Settings* vlmcSettings, QObject *parent = 0 );
void setProject( ProjectManager* projectManager );
void remove( const QString& projectFile );
const List& list() const;
private:
void removeFromRecentProjects( const QString &projectPath );
QString flattenProjectList() const;
public slots:
void projectLoaded( const QString& projectName, const QString& projectFile );
private slots:
void loadRecentProjects(const QVariant& recentProjects);
private:
Settings* m_settings;
ProjectManager* m_projectManager;
List m_recentsProjects;
};
#endif // RECENTPROJECTS_H
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