Skip to content

Commit

Permalink
Merge pull request #2238 from Wallacoloo/prompt-workingdir2
Browse files Browse the repository at this point in the history
Fix 'create working dir' prompt & move it from ConfigManager to GuiApplication
  • Loading branch information
Wallacoloo committed Aug 11, 2015
2 parents 65467eb + 4d3250b commit ed6ee79
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
6 changes: 6 additions & 0 deletions include/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ class EXPORT ConfigManager
return m_recentlyOpenedProjects;
}

// returns true if the working dir (e.g. ~/lmms) exists on disk
bool hasWorkingDir() const;

void addRecentlyOpenedProject( const QString & _file );

const QString & value( const QString & _class,
Expand All @@ -237,6 +240,9 @@ class EXPORT ConfigManager
void setGIGDir( const QString & gd );
void setSF2Dir( const QString & sfd );

// creates the working directory & subdirectories on disk.
void createWorkingDir();


private:
static ConfigManager * s_instanceOfMe;
Expand Down
43 changes: 22 additions & 21 deletions src/core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ void ConfigManager::upgrade()
m_version = LMMS_VERSION;
}

bool ConfigManager::hasWorkingDir() const
{
return QDir( m_workingDir ).exists();
}


void ConfigManager::setWorkingDir( const QString & _wd )
{
Expand Down Expand Up @@ -214,6 +219,20 @@ void ConfigManager::setSF2Dir(const QString &sfd)
}


void ConfigManager::createWorkingDir()
{
QDir().mkpath( m_workingDir );

QDir().mkpath( userProjectsDir() );
QDir().mkpath( userTemplateDir() );
QDir().mkpath( userSamplesDir() );
QDir().mkpath( userPresetsDir() );
QDir().mkpath( userGigDir() );
QDir().mkpath( userSf2Dir() );
QDir().mkpath( userVstDir() );
QDir().mkpath( userLadspaDir() );
}



void ConfigManager::addRecentlyOpenedProject( const QString & _file )
Expand Down Expand Up @@ -426,28 +445,10 @@ void ConfigManager::loadConfigFile()
searchPaths << artworkDir() << defaultArtworkDir();
QDir::setSearchPaths( "resources", searchPaths);

if( !QDir( m_workingDir ).exists() && gui &&
QMessageBox::question( 0,
MainWindow::tr( "Working directory" ),
MainWindow::tr( "The LMMS working directory %1 does not "
"exist. Create it now? You can change the directory "
"later via Edit -> Settings." ).arg( m_workingDir ),
QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
// Create any missing subdirectories in the working dir, but only if the working dir exists
if( hasWorkingDir() )
{
QDir().mkpath( m_workingDir );
}

if( QDir( m_workingDir ).exists() )
{
QDir().mkpath( userProjectsDir() );
QDir().mkpath( userTemplateDir() );
QDir().mkpath( userSamplesDir() );
QDir().mkpath( userPresetsDir() );
QDir().mkpath( userGigDir() );
QDir().mkpath( userSf2Dir() );
QDir().mkpath( userVstDir() );
QDir().mkpath( userLadspaDir() );

createWorkingDir();
}

upgrade();
Expand Down
13 changes: 13 additions & 0 deletions src/gui/GuiApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "AutomationEditor.h"
#include "BBEditor.h"
#include "ConfigManager.h"
#include "ControllerRackView.h"
#include "FxMixerView.h"
#include "InstrumentTrack.h"
Expand All @@ -40,6 +41,7 @@
#include "SongEditor.h"

#include <QApplication>
#include <QMessageBox>
#include <QSplashScreen>

GuiApplication* GuiApplication::s_instance = nullptr;
Expand All @@ -52,6 +54,17 @@ GuiApplication* GuiApplication::instance()

GuiApplication::GuiApplication()
{
// prompt the user to create the LMMS working directory (e.g. ~/lmms) if it doesn't exist
if ( !ConfigManager::inst()->hasWorkingDir() &&
QMessageBox::question( NULL,
tr( "Working directory" ),
tr( "The LMMS working directory %1 does not "
"exist. Create it now? You can change the directory "
"later via Edit -> Settings." ).arg( ConfigManager::inst()->workingDir() ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes ) == QMessageBox::Yes)
{
ConfigManager::inst()->createWorkingDir();
}
// Init style and palette
LmmsStyle* lmmsstyle = new LmmsStyle();
QApplication::setStyle(lmmsstyle);
Expand Down

0 comments on commit ed6ee79

Please sign in to comment.