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

Fix recent projects list.

It is now based on the project path, and therefor supports projects with
the same name.
This will need to go away from ProjectManager though, as it's a VLMC
wide notion, and does not belong in a project specific class
parent 182368a5
......@@ -324,7 +324,8 @@ 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", "" );
VLMC_CREATE_PRIVATE_PREFERENCE_STRING( "private/RecentsProjects", "" );
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" ),
......
......@@ -119,14 +119,13 @@ WelcomePage::loadRecentsProjects()
{
m_ui.projectsListWidget->clear();
ProjectManager* pm = Project::getInstance()->projectManager();
QStringList recents = pm->recentsProjects();
const ProjectManager::RecentProjectsList& recents = pm->recentsProjects();
for ( int i = 0; i < recents.count(); ++i )
{
QFileInfo fi( recents.at( i ) );
QListWidgetItem* item = new QListWidgetItem( fi.fileName() );
item->setData( FilePath, fi.absoluteFilePath() );
ProjectManager::RecentProject project = recents.at( i );
QListWidgetItem* item = new QListWidgetItem( project.name );
item->setData( FilePath, project.filePath );
m_ui.projectsListWidget->addItem( item );
}
}
......
......@@ -104,6 +104,7 @@ ProjectManager::ProjectManager( Settings* projectSettings, Settings* vlmcSetting
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,7 +123,7 @@ ProjectManager::setProjectManagerUi( IProjectManagerUiCb *projectManagerUi )
}
QStringList
const ProjectManager::RecentProjectsList&
ProjectManager::recentsProjects() const
{
return m_recentsProjects;
......@@ -138,7 +139,7 @@ ProjectManager::loadWorkflow()
loadTimeline( root );
if ( m_projectFile != NULL )
{
appendToRecentProject( projectName() );
appendToRecentProject( projectName(), m_projectFile->fileName() );
savedState = true;
}
else
......@@ -149,12 +150,10 @@ ProjectManager::loadWorkflow()
}
void
ProjectManager::removeProject( const QString& project )
ProjectManager::removeProject( const QString& projectPath )
{
// Remove all occurence of fileName
m_recentsProjects.removeAll( project );
Core::getInstance()->settings()->setValue( SETTINGS_RECENTS, m_recentsProjects );
removeFromRecentProjects( projectPath );
Core::getInstance()->settings()->setValue( SETTINGS_RECENTS, flattenProjectList() );
}
void
......@@ -221,15 +220,46 @@ ProjectManager::createAutoSaveOutputFileName( const QString& baseName ) const
}
void
ProjectManager::appendToRecentProject( const QString& projectName )
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
m_recentsProjects.removeAll( projectName );
m_recentsProjects.prepend( projectName );
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, m_recentsProjects );
Core::getInstance()->settings()->setValue( SETTINGS_RECENTS, flattenProjectList() );
Core::getInstance()->settings()->save();
}
......@@ -343,7 +373,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 );
appendToRecentProject( projectName, m_projectFile->fileName() );
}
void
......@@ -428,6 +458,32 @@ 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()
{
......
......@@ -83,16 +83,23 @@ class ProjectManager : public QObject
Q_DISABLE_COPY( ProjectManager )
public:
static const QString unNamedProject;
static const QString unSavedProject;
static const QString backupSuffix;
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& fileName );
QStringList recentsProjects() const;
void removeProject( const QString& projectPath );
const RecentProjectsList& recentsProjects() const;
bool closeProject();
void save();
......@@ -119,7 +126,7 @@ private:
*/
void saveTimeline(QXmlStreamWriter& project);
static bool isBackupFile( const QString& projectFile );
void appendToRecentProject( const QString& projectName );
void appendToRecentProject(const QString& projectName , const QString &projectPath);
/**
* \brief Get the project name
*
......@@ -134,10 +141,16 @@ 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;
QStringList m_recentsProjects;
// 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;
......
......@@ -63,7 +63,6 @@ class SettingValue : public QObject
Runtime = 1 << 5, ///< Defines a variable that is not meant to be saved
};
Q_DECLARE_FLAGS( Flags, Flag );
/**
* \brief Constructs a setting value with its default value and description
*
......
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