Commit c85eb301 authored by Stéphane Albert's avatar Stéphane Albert

ENH: Move factorized code into Commo/Core/i18nApplication; Removed Code/Common/Application.

parent cf02dfd9
#############################################################################
# Input files.
set( Catalogue_SOURCES
mvdApplication.cxx
mvdCatalogueApplication.cxx
mvdMainWindow.cxx
)
# Headers for classes with Q_OBJECT macro (needs to go to Qt moc)
set( Catalogue_HEADERS_MOC
mvdApplication.h
mvdCatalogueApplication.h
mvdMainWindow.h
)
......
......@@ -41,7 +41,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdApplication.h"
#include "mvdCatalogueApplication.h"
#include "mvdMainWindow.h"
/*****************************************************************************/
......@@ -54,14 +54,9 @@
int
main( int argc, char* argv[] )
{
mvd::Application application( argc, argv );
mvd::CatalogueApplication application( argc, argv );
//
// Force numeric options of locale to "C"
// See issue #635
//
// TODO: Move into I18nApplication.
setlocale( LC_NUMERIC, "C" );
application.Initialize();
#if 0
// TODO: 1) MVD2-viewer: Factorize settings loading between Viewer & Catalogue // Check if the application have a settings file already available
......@@ -81,7 +76,7 @@ main( int argc, char* argv[] )
mvd::MainWindow mainWindow;
/*
#if 0
// TODO: 1) MVD2-viewer: Factorize cache-dir search between Viewer & Catalogue.
if (!appHasSettingsFile || appHasIncorrectCacheDir)
{
......@@ -103,7 +98,7 @@ main( int argc, char* argv[] )
// Save the cache directory into the settings file
application.WriteCacheDirIntoSettings();
}
*/
#endif
// Show window.
mainWindow.show();
......
......@@ -16,7 +16,7 @@
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "mvdApplication.h"
#include "mvdCatalogueApplication.h"
/*****************************************************************************/
......@@ -41,7 +41,7 @@ namespace mvd
{
/*
TRANSLATOR mvd::Application
TRANSLATOR mvd::CatalogueApplication
Necessary for lupdate to be aware of C++ namespaces.
......@@ -60,53 +60,31 @@ namespace mvd
/* CLASS IMPLEMENTATION SECTION */
/*******************************************************************************/
Application
::Application( int& argc, char** argv ) :
CatalogueApplication
::CatalogueApplication( int& argc, char** argv ) :
I18nApplication( argc, argv )
{
InitializeCore();
}
/*******************************************************************************/
Application
::~Application()
CatalogueApplication
::~CatalogueApplication()
{
}
/*******************************************************************************/
void
Application
::InitializeCore()
CatalogueApplication
::virtual_InitializeCore()
{
setObjectName( "mvd::Application" );
setObjectName( "CatalogueApplication" );
//
// Setup application tags.
//
QCoreApplication::setApplicationName(
PROJECT_NAME "-Catalogue"
InitializeCore(
PROJECT_NAME, Monteverdi2_VERSION_STRING,
"OrfeoToolBox", "orfeo-toolbox.org"
);
QCoreApplication::setApplicationVersion(
Monteverdi2_VERSION_STRING
);
//
// Setup organization tags.
//
QCoreApplication::setOrganizationName(
"OrfeoToolBox"
);
QCoreApplication::setOrganizationDomain(
"orfeo-toolbox.org"
);
#ifndef Q_WS_MAC
setWindowIcon(QIcon(QLatin1String(":/images/application_icon")));
#endif
}
/*******************************************************************************/
/* SLOTS */
......
......@@ -17,8 +17,8 @@
=========================================================================*/
#ifndef __mvdApplication_h
#define __mvdApplication_h
#ifndef __mvdCatalogueApplication_h
#define __mvdCatalogueApplication_h
//
// Configuration include.
......@@ -44,7 +44,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "Core/mvdI18nApplication.h"
#include "Core/mvdApplication.h"
/*****************************************************************************/
......@@ -64,10 +64,10 @@ namespace mvd
/*****************************************************************************/
/* CLASS DEFINITION SECTION */
/** \class Application
/** \class CatalogueApplication
*
*/
class Monteverdi2_EXPORT Application
class Monteverdi2_EXPORT CatalogueApplication
: public I18nApplication
{
......@@ -91,10 +91,10 @@ public:
* \param argc Command-line argument count in the argv array.
* \param argv Array of command-argument (whitespace-separated) strings.
*/
Application( int& argc, char** argv );
CatalogueApplication( int& argc, char** argv );
/** \brief Destructor. */
virtual ~Application();
virtual ~CatalogueApplication();
/*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/
......@@ -117,14 +117,13 @@ protected:
// Protected attributes.
protected:
virtual void virtual_InitializeCore();
/*-[ PRIVATE SECTION ]-----------------------------------------------------*/
//
// Private methods.
private:
/**
*/
void InitializeCore();
//
// Private attributes.
......@@ -143,4 +142,4 @@ private slots:
} // end namespace 'mvd'
#endif // __Application_h
#endif // __CatalogueApplication_h
......@@ -46,12 +46,17 @@ main( int argc, char* argv[] )
{
mvd::Application application( argc, argv );
application.Initialize();
/*
// INFO: Moved (fatorized) into I18nApplcation.
//
// Force numeric options of locale to "C"
// See issue #635
//
// TODO: Move into I18nApplication.
setlocale( LC_NUMERIC, "C" );
*/
// TODO: 1) MVD2-viewer: Factorize settings loading between Viewer & Catalogue // Check if the application have a settings file already available
bool appHasSettingsFile = application.HasSettingsFile();
......
......@@ -58,6 +58,8 @@ const char* Application::DATASET_EXT = ".ds";
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION */
#if 0
/*****************************************************************************/
void
Application
......@@ -136,23 +138,27 @@ Application::LoadDatasetModel( const QString& imageFilename,
return model;
}
#endif
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
/*******************************************************************************/
Application
::Application( int& argc, char** argv ) :
I18nApplication( argc, argv ),
I18nApplication( argc, argv )//,
#if 0
m_Model( NULL )
#endif
{
#if 0
InitializeCore();
#endif
QObject::connect(
this, SIGNAL( aboutToQuit() ),
this, SLOT( OnAboutToQuit() )
);
InitializeModel();
}
/*******************************************************************************/
......@@ -162,6 +168,7 @@ Application
}
/*******************************************************************************/
#if 0
void
Application
::SetModel( AbstractModel* model )
......@@ -177,15 +184,28 @@ Application
emit SelectedModelChanged( m_Model );
}
#endif
/*******************************************************************************/
void
Application
::InitializeCore()
::virtual_InitializeCore()
{
setObjectName( "Application" );
setObjectName( "ViewerApplication" );
//
InitializeCore(
PROJECT_NAME, Monteverdi2_VERSION_STRING,
"OrfeoToolBox", "orfeo-toolbox.org"
);
}
/*******************************************************************************/
#if 0
void
Application
::InitializeCore()
{
//
// Setup application tags.
//
QCoreApplication::setApplicationName(
......@@ -209,16 +229,12 @@ Application
#endif
}
#endif
/*******************************************************************************/
void
bool
Application
::InitializeModel()
{
}
/*******************************************************************************/
bool Application::HasSettingsFile()
::HasSettingsFile()
{
// The settings file should contain the cacheDir key to be valid
QSettings settings;
......@@ -227,19 +243,68 @@ bool Application::HasSettingsFile()
}
/*******************************************************************************/
void Application::ReadCacheDirFromSettings()
void
Application
::ReadCacheDirFromSettings()
{
QSettings settings;
QString cacheDirSetting = settings.value("cacheDir").toString();
m_CacheDir.setPath(cacheDirSetting);
GetCacheDir().setPath(cacheDirSetting);
}
/*******************************************************************************/
void Application::WriteCacheDirIntoSettings()
{
QSettings settings;
settings.setValue("cacheDir", m_CacheDir.path());
settings.setValue("cacheDir", GetCacheDir().path());
}
/*******************************************************************************/
bool
Application
::CheckCacheDirIsCorrect()
{
QDir dir = GetCacheDir();
if (!TestDirExistenceAndWriteAcess(dir))
{
return false;
}
else
{
// Check if this directory has the good name
if (GetCacheDir().dirName().compare(QString(I18nApplication::DEFAULT_CACHE_DIR_NAME)))
{
return false;
}
}
return true;
}
/*******************************************************************************/
bool
Application
::TestDirExistenceAndWriteAcess( QDir dir)
{
// Check if this directory exists
if (!dir.exists())
{
return false;
}
// Check if we can write in this directory
if (dir.mkdir("testWriteAccess"))
{ // ok this repository is correct
dir.rmdir("testWriteAccess");
}
else
{ // ko this repository is not correct
return false;
}
return true;
}
/*******************************************************************************/
/* SLOTS */
......
......@@ -99,6 +99,7 @@ public:
/** \brief Destructor. */
virtual ~Application();
#if 0
/**
*/
inline const AbstractModel* GetModel() const;
......@@ -116,6 +117,7 @@ public:
*/
template< typename TModel >
inline TModel* GetModel();
#endif
/**
*
......@@ -132,6 +134,23 @@ public:
*/
void WriteCacheDirIntoSettings();
/**
* \brief Check if the cache directory is valid.
*
* \return true if the cache directory is correct
*/
// TODO: Remove method when class is upgraded to I18nApplication fatorized code.
bool CheckCacheDirIsCorrect();
/**
* \brief Test if the application can write in the directory provided.
*
* \param dir input directory
* \return true if the directory can be used
*/
// TODO: Remove method when class is upgraded to I18nApplication fatorized code.
bool TestDirExistenceAndWriteAcess( QDir dir);
//
// STATIC METHODS.
......@@ -151,6 +170,7 @@ public:
*/
inline static const Application* ConstInstance();
#if 0
/**
*/
static
......@@ -164,20 +184,25 @@ public:
DatasetModel* LoadDatasetModel( const QString& imageFilename,
int width,
int height );
#endif
//
// PUBLIC SLOTS.
public slots:
#if 0
/**
*/
// Method could be inline but it's better not new/delete in inline
// methods (heap and memory-alignment contexts).
void SetModel( AbstractModel* model );
#endif
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
// Signals.
signals:
#if 0
/**
*/
void AboutToChangeSelectedModel( const AbstractModel* );
......@@ -185,6 +210,7 @@ signals:
/**
*/
void SelectedModelChanged( AbstractModel* );
#endif
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
......@@ -192,6 +218,8 @@ signals:
// Protected methods.
protected:
virtual void virtual_InitializeCore();
//
// Protected attributes.
protected:
......@@ -201,21 +229,20 @@ protected:
//
// Private methods.
private:
#if 0
/**
*/
void InitializeCore();
/**
*/
void InitializeModel();
#endif
//
// Private attributes.
private:
#if 0
/**
*/
AbstractModel* m_Model;
#endif
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
......@@ -248,6 +275,7 @@ Application
return I18nApplication::ConstInstance< Application >();
}
#if 0
/*****************************************************************************/
inline
const AbstractModel*
......@@ -285,6 +313,7 @@ Application
{
return qobject_cast< TModel* >( m_Model );
}
#endif
/*****************************************************************************/
......
......@@ -99,7 +99,7 @@ MainWindow
QString defaultCacheDirLocStr (QDir::toNativeSeparators(QDir::homePath()));
QString defaultCacheDirStr (defaultCacheDirLocStr);
defaultCacheDirStr.append(QDir::separator());
defaultCacheDirStr.append(Application::ConstInstance()->GetCacheDirName());
defaultCacheDirStr.append( I18nApplication::DEFAULT_CACHE_DIR_NAME );
int ret;
......@@ -199,15 +199,15 @@ MainWindow
// Connect Appllication and MainWindow when selected model is about
// to change.
QObject::connect(
qApp, SIGNAL( AboutToChangeSelectedModel( const AbstractModel* ) ),
this, SLOT( OnAboutToChangeSelectedModel( const AbstractModel* ) )
qApp, SIGNAL( AboutToChangeModel( const AbstractModel* ) ),
this, SLOT( OnAboutToChangeModel( const AbstractModel* ) )
);
// Connect Application and MainWindow when selected model has been
// changed.
QObject::connect(
qApp, SIGNAL( SelectedModelChanged( AbstractModel* ) ),
this, SLOT( OnSelectedModelChanged( AbstractModel* ) )
qApp, SIGNAL( ModelChanged( AbstractModel* ) ),
this, SLOT( OnModelChanged( AbstractModel* ) )
);
// Show the progress dialog when a new image is loaded
......@@ -537,7 +537,7 @@ MainWindow
/*****************************************************************************/
void
MainWindow
::OnAboutToChangeSelectedModel( const AbstractModel* )
::OnAboutToChangeModel( const AbstractModel* )
{
//
// COLOR SETUP.
......@@ -702,7 +702,7 @@ MainWindow
/*****************************************************************************/
void
MainWindow
::OnSelectedModelChanged( AbstractModel* model )
::OnModelChanged( AbstractModel* model )
{
if( model==NULL )
return;
......
......@@ -287,13 +287,13 @@ private slots:
void OnColorDynamicsVisibilityChanged ( bool );
/** */
void OnAboutToChangeSelectedModel( const AbstractModel* );
void OnAboutToChangeModel( const AbstractModel* );
/** */
void OnModelLoaded( AbstractModel* );
/** */
void OnSelectedModelChanged( AbstractModel* );
void OnModelChanged( AbstractModel* );
/** */
void OnUserCoordinatesEditingFinished();
......
......@@ -100,7 +100,9 @@ PreferencesDialog
m_CacheDirRootModified = true;
m_CacheDirRoot = cacheDirStr;
QDir displayedDir (cacheDirStr);
QDir treeDir( displayedDir.filePath( Application::Instance()->GetCacheDirName() ) );
QDir treeDir(
displayedDir.filePath( I18nApplication::DEFAULT_CACHE_DIR_NAME )
);
m_UI->cacheDirPathLineEdit->setText(treeDir.absolutePath());
break;
}
......
......@@ -6,7 +6,6 @@ set( Common_Core_SOURCES
mvdAbstractImageModel.cxx
mvdAbstractModel.cxx
mvdAlgorithm.cxx
mvdApplication.cxx
mvdDatasetDescriptor.cxx
mvdDatasetModel.cxx
mvdHistogramModel.cxx
......@@ -27,7 +26,6 @@ set( Common_Core_HEADERS_MOC
mvdAbstractImageModel.h
mvdAbstractModel.h
mvdAlgorithm.h
mvdApplication.h
mvdDatasetDescriptor.h
mvdDatasetModel.h
mvdHistogramModel.h
......
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.