Commit 4280d8c8 authored by Stéphane Albert's avatar Stéphane Albert

ENH: Removed obsolete CacheDir management.

parent f4a7a753
......@@ -126,115 +126,13 @@ main( int argc, char* argv[] )
//
// 3. Initialize cache directory.
/*
try
{
mainWindow.SetupCacheDir();
}
catch( std::exception& exc )
{
QMessageBox::critical(
&mainWindow,
QCoreApplication::translate(
"Monteverdi",
"Monteverdi - Critical error!"
),
QCoreApplication::translate(
"Monteverdi",
"Error while creating cache repository.\n\n"
"%1\n\n"
"Application will exit!"
)
.arg( exc.what() )
);
return ERROR_CODE_CACHE_DIR;
}
*/
//
// N/A
//
// 4. Initialize database.
/*
try
{
mvd::CountType nb = application->OpenDatabase();
if( nb>0 )
{
QMessageBox::StandardButton button =
QMessageBox::warning(
&mainWindow,
QCoreApplication::translate(
"Monteverdi",
"Monteverdi - Warning!"
),
QCoreApplication::translate(
"Monteverdi",
"There are %1 outdated dataset(s) in cache-directory.\n\n"
"Please remove cache-directory '%2' and restart Monteverdi\n\n"
"Do you want to delete cache-directory '%2' before quitting Monteverdi?"
).arg( nb ).arg( application->GetCacheDir().path() ),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes
);
if( button==QMessageBox::Yes )
{
if( application->GetCacheDir()==QDir::home() )
{
// throw std::runtime_error(
// mvd::ToStdString(
// QCoreApplication::translate(
// "Monteverdi",
// "Tryed to remove home dir."
// )
// )
// );
QMessageBox::critical(
&mainWindow,
QCoreApplication::translate(
"Monteverdi",
"Monteverdi - Critical error!"
),
QCoreApplication::translate(
"Monteverdi",
"Your Monteverdi cache-directory is set to your home directory '%1'. Deletion of cache-directory is aborted to avoid unrecoverable loss of all your account data.\n\nIt is generally a bad idea to set Monteverdi cache-directory to your home directory. Please choose another sub-directory.\n\nApplication will now exit."
)
.arg( application->GetCacheDir().path() ),
QMessageBox::Ok
);
}
else
{
itksys::SystemTools::RemoveADirectory(
QFile::encodeName( application->GetCacheDir().path() ).constData()
);
}
}
return ERROR_CODE_DATABASE;
}
}
catch( std::exception& exc )
{
QMessageBox::critical(
&mainWindow,
QCoreApplication::translate(
"Monteverdi",
"Monteverdi - Critical error!"
),
QCoreApplication::translate(
"Monteverdi",
"Failed to open Monteverdi database.\n\nApplication will now exit!\n\n%2\n\nPlease, remove your Monteverdi cache-directory."
)
.arg( exc.what() ),
QMessageBox::Ok
);
return ERROR_CODE_DATABASE;
}
*/
//
// N.A.
//
// 5. Show window.
......
......@@ -72,7 +72,6 @@ const char* I18nCoreApplication::DATASET_EXT = ".ds";
const char* I18nCoreApplication::SETTINGS_KEYS[ SETTINGS_KEY_COUNT ] =
{
"cacheDir",
"geoidPath",
"geoidPathActive",
"overviewsEnabled",
......@@ -89,22 +88,6 @@ const char* I18nCoreApplication::SETTINGS_KEYS[ SETTINGS_KEY_COUNT ] =
I18nCoreApplication* I18nCoreApplication::m_Instance = NULL;
/*******************************************************************************/
bool
I18nCoreApplication
::IsCacheDirValid( const QString& path )
{
QDir dir( path );
QFileInfo fileInfo( path );
return
fileInfo.exists() &&
fileInfo.isDir() &&
fileInfo.isReadable() &&
fileInfo.isWritable() &&
dir.dirName()==I18nCoreApplication::DEFAULT_CACHE_DIR_NAME;
}
/*******************************************************************************/
bool
I18nCoreApplication
......@@ -168,17 +151,12 @@ I18nCoreApplication
/*****************************************************************************/
QString
I18nCoreApplication
::DatasetPathName( QString& path,
QString& name,
::DatasetPathName( QString& name,
const QString& imageFilename )
{
// convenient QFileInfo
QFileInfo fileInfo( imageFilename );
// Dataset is stored into application cache-directory.
// E.g. '$HOME/<CACHE_DIR>'
path = I18nCoreApplication::Instance()->GetCacheDir().path();
// get the md5 of the filename
QByteArray result =
QCryptographicHash::hash( fileInfo.absoluteFilePath().toAscii(),
......@@ -237,7 +215,7 @@ I18nCoreApplication
/*****************************************************************************/
DatasetModel*
I18nCoreApplication
::LoadDatasetModel( const QString& imageFilename,
::LoadDatasetModel( const QString & imageFilename,
int width,
int height,
bool forceCreate )
......@@ -249,8 +227,7 @@ I18nCoreApplication
QString path;
QString name;
I18nCoreApplication::DatasetPathName( path, name, imageFilename );
qDebug() << "Dataset path:" << path;
I18nCoreApplication::DatasetPathName( name, imageFilename );
qDebug() << "Dataset name:" << name;
QString pathname( QDir( path ).filePath( name ) );
......@@ -261,7 +238,7 @@ I18nCoreApplication
try
{
// try if the filename is valid
VectorImageModel::EnsureValidImage(imageFilename);
VectorImageModel::EnsureValidImage( imageFilename );
// get the basename from the filename to be used as an Alias
QFileInfo finfo( imageFilename );
......@@ -294,9 +271,9 @@ I18nCoreApplication
/*****************************************************************************/
void
I18nCoreApplication
::DeleteDatasetModel( const QString& hash )
::DeleteDatasetModel( const QString & path, const QString & hash )
{
QFileInfo finfo( I18nCoreApplication::ConstInstance()->GetCacheDir(), hash );
QFileInfo finfo( path, hash );
QDir dir( finfo.filePath() );
......@@ -433,7 +410,6 @@ I18nCoreApplication
I18nCoreApplication
::I18nCoreApplication( QCoreApplication* qtApp ) :
QObject( qtApp ),
m_CacheDir(),
m_Settings( NULL ),
m_Model( NULL ),
m_IsRunningFromBuildDir( false )
......@@ -510,58 +486,6 @@ I18nCoreApplication
emit ModelChanged( m_Model );
}
/*******************************************************************************/
bool
I18nCoreApplication
::MakeCacheDir( const QString& path )
{
// qDebug() << this << "::MakeCacheDir(" << path << ")";
//
// Check path.
QDir homeDir( path );
if (!homeDir.exists())
SystemError( ToStdString( QString( "('%1')" ).arg( homeDir.path() ) ) );
if (homeDir.dirName() == I18nCoreApplication::DEFAULT_CACHE_DIR_NAME )
qWarning() << tr("The selected directory seems to be an previous mvd2 directory, nevertheless we will create a new mvd2 repository into the selected directory.") ;
//
// Create cache-dir.
bool isNew = I18nCoreApplication::MakeDirTree(
homeDir.path(),
I18nCoreApplication::DEFAULT_CACHE_DIR_NAME,
&m_CacheDir
);
//
// Remember cache-dir.
StoreSettingsKey(
I18nCoreApplication::SETTINGS_KEY_CACHE_DIR,
QDir::cleanPath( m_CacheDir.path() )
);
//
// Construct result-dir path.
I18nCoreApplication::MakeDirTree(
m_CacheDir.path(),
I18nCoreApplication::DEFAULT_CACHE_RESULT_DIR_NAME,
&m_ResultsDir
);
//
// Remember result-dir
StoreSettingsKey(
I18nCoreApplication::SETTINGS_KEY_RESULTS_DIR,
QDir::cleanPath( m_ResultsDir.path() )
);
//
// Result.
return isNew;
}
/*******************************************************************************/
bool
I18nCoreApplication
......@@ -875,24 +799,6 @@ I18nCoreApplication
this
);
//
// Restore cache directory.
QVariant value(
RetrieveSettingsKey( I18nCoreApplication::SETTINGS_KEY_CACHE_DIR )
);
if( !value.isNull() )
{
QString path( value.toString() );
qDebug() << "Settings/cacheDir:" << path;
if( I18nCoreApplication::IsCacheDirValid( path ) )
{
m_CacheDir.setPath( path );
}
}
//
// Restore result directory.
QVariant resultDir(
......
......@@ -112,7 +112,6 @@ class Monteverdi_EXPORT I18nCoreApplication
public:
enum SettingsKey
{
SETTINGS_KEY_CACHE_DIR =0,
SETTINGS_KEY_GEOID_PATH,
SETTINGS_KEY_GEOID_PATH_ACTIVE,
SETTINGS_KEY_OVERVIEWS_ENABLED,
......@@ -206,15 +205,6 @@ public:
// APPLICATION CACHE-DIRECTORY.
//
/**
* \brief Create cache directory if not already existing.
*
* \param cacheDirStr path where the function will create the cache directory
* \return true if cache directory has just been created or false if
* it was already existing.
*/
bool MakeCacheDir( const QString& cacheDirStr );
/**
* \brief setup elevation management
......@@ -256,18 +246,10 @@ public:
// TODO: Move method into Application class.
inline QVariant RetrieveSettingsKey( const QString & key ) const;
/**
*/
inline bool IsCacheDirValid() const;
//
// STATIC methods.
//
/**
*/
static bool IsCacheDirValid( const QString& path );
/**
*/
static bool IsResultsDirValid( const QString& path );
......@@ -304,8 +286,7 @@ public:
* pathname of image file.
*/
static
QString DatasetPathName( QString& path,
QString& name,
QString DatasetPathName( QString& name,
const QString& imageFilename );
/**
......@@ -337,24 +318,12 @@ public:
/**
*/
static
void DeleteDatasetModel( const QString& hash );
void DeleteDatasetModel( const QString & path, const QString & hash );
//
// NON-STATIC methods.
//
/**
* \brief Get the cache directory.
*
* \return Return the cache directory.
*/
inline const QDir& GetCacheDir() const;
/**
*/
// TODO: Remove method when Viewer/Application is updated to reuse factorized code of I18nCoreApplication.
inline QDir& GetCacheDir();
/**
* \brief Get the results directory (where output from
* OTBApplicaitons are stored).
......@@ -525,12 +494,6 @@ private:
*/
static I18nCoreApplication* m_Instance;
/**
* \brief Directory where all cached files are stored (repository of datasets).
*/
// TODO: Move I18nCoreApplication::m_CacheDir to private section.
QDir m_CacheDir;
/**
* \brief Directory where all result files from OTB applications are
* stored
......@@ -641,14 +604,6 @@ I18nCoreApplication
return qobject_cast< TModel* >( m_Model );
}
/*****************************************************************************/
const QDir&
I18nCoreApplication
::GetCacheDir() const
{
return m_CacheDir;
}
/*****************************************************************************/
const QDir&
I18nCoreApplication
......@@ -657,23 +612,6 @@ I18nCoreApplication
return m_ResultsDir;
}
/*****************************************************************************/
inline
bool
I18nCoreApplication
::IsCacheDirValid() const
{
return I18nCoreApplication::IsCacheDirValid( m_CacheDir.path() );
}
/*****************************************************************************/
QDir&
I18nCoreApplication
::GetCacheDir()
{
return m_CacheDir;
}
/*****************************************************************************/
QDir&
I18nCoreApplication
......
......@@ -294,63 +294,6 @@ I18nMainWindow
QMainWindow::closeEvent( event );
}
/*****************************************************************************/
void
I18nMainWindow
::SetupCacheDir()
{
if( I18nCoreApplication::ConstInstance()->IsCacheDirValid() )
return;
QFileInfo fileInfo( QDir::home(), I18nApplication::DEFAULT_CACHE_DIR_NAME );
QDir dir( fileInfo.dir() );
QMessageBox messageBox;
messageBox.setWindowTitle( tr( "Welcome new Monteverdi user!" ) );
messageBox.setText(
tr(
"Monteverdi maintains a repository where cached data related to images is stored "
"(such as, for example, color-settings, histogram, quicklook etc.)."
"\n\n"
"Default cache-directory location is: '%1'."
"\n\n"
"Warning:\n"
"- Your account needs to have write access to this directory;\n"
"- Please be aware that this directory can consume significant disk "
"space."
)
.arg( dir.path() )
);
messageBox.setInformativeText(
tr( "Do you want to specify a custom repository location?" )
);
messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
messageBox.setDefaultButton( QMessageBox::No );
if( messageBox.exec()==QMessageBox::Yes )
{
QString path(
I18nMainWindow::GetExistingDirectory(
this,
tr(
"Please, select directory where the Monteverdi"
" cache repository will be stored."
),
dir.path()
)
);
if( !path.isEmpty() )
dir.setPath( path );
}
I18nApplication::Instance()->MakeCacheDir( dir.path() );
}
/*****************************************************************************/
void
I18nMainWindow
......
......@@ -98,10 +98,6 @@ public:
*/
void Initialize();
/**
*/
void SetupCacheDir();
/**
* \brief This is a convenience static method that will return an
* existing directory path selected by the user.
......
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