27 #include <boost/foreach.hpp>  
   30 #include "../../common/Exception.h" 
   31 #include "../../common/Translator.h" 
   32 #include "../../common/TerraLib.h" 
   33 #include "../../common/SystemApplicationSettings.h" 
   34 #include "../../common/UserApplicationSettings.h" 
   35 #include "../../common/Logger.h" 
   36 #include "../../dataaccess/serialization/xml/Serializer.h" 
   37 #include "../../plugin/PluginManager.h" 
   38 #include "../../plugin/PluginInfo.h" 
   39 #include "../../srs/Config.h" 
   40 #include "../widgets/help/AssistantHelpManagerImpl.h" 
   41 #include "../widgets/help/HelpManager.h" 
   42 #include "../widgets/Utils.h" 
   43 #include "../widgets/utils/ScopedCursor.h" 
   54 #include <QtCore/QDir> 
   55 #include <QtCore/QResource> 
   56 #include <QtGui/QApplication> 
   57 #include <QtGui/QIcon> 
   58 #include <QtGui/QMessageBox> 
   59 #include <QtGui/QWidget> 
   60 #include <QtGui/QMenu> 
   63 #include <boost/filesystem.hpp> 
   69     m_msgBoxParentWidget(0),
 
   71     m_selectionColor(QColor(0, 255, 0)),
 
   76     throw Exception(
TR_QT_AF(
"Can not start another instance of the TerraLib Application Controller!"));
 
   95   m_appConfigFile = configFileName;
 
  100   m_msgBoxParentWidget = w;
 
  105   registerToolBar(
id, bar);
 
  115   QToolBar* b = getToolBar(
id);
 
  118     throw Exception(
TR_QT_AF(
"There is already a tool bar registered with the same name!"));
 
  120   m_toolbars[id] = bar;
 
  125   std::map<QString, QToolBar*>::const_iterator it = m_toolbars.find(
id);
 
  127   return (it != m_toolbars.end()) ? it->second : 0;
 
  132   std::vector<QToolBar*> res;
 
  133   std::map<QString, QToolBar*>::const_iterator it;
 
  135   for(it = m_toolbars.begin(); it != m_toolbars.end(); ++it)
 
  136     res.push_back(it->second);
 
  143   std::map<QString, QToolBar*>::iterator it = m_toolbars.find(
id);
 
  145   if(it != m_toolbars.end())
 
  146     m_toolbars.erase(it);
 
  151   m_menus.push_back(mnu);
 
  156   std::vector<QMenu*>::const_iterator it;
 
  159   for(it = m_menus.begin(); it != m_menus.end(); ++it)
 
  168   std::vector<QMenuBar*>::const_iterator it_bar;
 
  170   for(it_bar = m_menuBars.begin(); it_bar != m_menuBars.end(); ++it_bar)
 
  183   QMenu* mnu = findMenu(
id);
 
  187     if(!m_menuBars.empty())
 
  192       m_menus.push_back(mnu);
 
  201   m_menuBars.push_back(bar);
 
  206   throw Exception(
"Not implemented yet.");
 
  211   return m_menuBars[0];
 
  216   for(
size_t i=0; i<m_menus.size(); i++)
 
  224   for(
size_t i=0; i<m_menuBars.size(); i++)
 
  237   std::set<QObject*>::const_iterator it = m_applicationItems.find(obj);
 
  239   if(it != m_applicationItems.end())
 
  242   m_applicationItems.insert(obj);
 
  249   std::set<QObject*>::iterator it = m_applicationItems.find(obj);
 
  251   if(it == m_applicationItems.end())
 
  254   m_applicationItems.erase(it);
 
  274   if(m_appConfigFile.empty())
 
  286   qApp->setApplicationName(m_appName);
 
  290   qApp->setOrganizationName(m_appOrganization);
 
  322     if(!m_appHelpFile.isEmpty())
 
  333   catch(
const std::exception& e)
 
  337     QString msgErr(tr(
"Error loading application help system: %1"));
 
  339     msgErr = msgErr.arg(e.what());
 
  341     QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
 
  351     if(!m_appIconThemeDir.isEmpty())
 
  353       QStringList ithemes = QIcon::themeSearchPaths();
 
  355       ithemes.push_back(m_appIconThemeDir);
 
  357       QIcon::setThemeSearchPaths(ithemes);
 
  364     if(iconTheme.isEmpty())
 
  365       QIcon::setThemeName(m_appDefaultIconTheme);
 
  367       QIcon::setThemeName(iconTheme);
 
  373     if(!iconSize.empty())
 
  375       QString sh = QString(
"QToolBar { qproperty-iconSize: ") + iconSize.c_str() + 
"px " + iconSize.c_str() + 
"px; }";
 
  376       qApp->setStyleSheet(sh);
 
  385       m_defaultSRID = srid.toInt();
 
  389     if(selectionColor.isEmpty())
 
  392     if(!selectionColor.isEmpty())
 
  393       m_selectionColor = QColor(selectionColor);
 
  397   catch(
const std::exception& e)
 
  401     QString msgErr(tr(
"Error loading application icon theme: %1"));
 
  403     msgErr = msgErr.arg(e.what());
 
  405     QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
 
  413     if(!m_appDatasourcesFile.empty())
 
  422   catch(
const std::exception& e)
 
  426     QString msgErr(tr(
"Error loading the registered data sources: %1"));
 
  428     msgErr = msgErr.arg(e.what());
 
  430     QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
 
  433   QSettings s(QSettings::IniFormat, QSettings::UserScope, m_appOrganization, m_appName);
 
  435   QFileInfo info(s.fileName());
 
  440   m_initialized = 
true;
 
  447   bool loadPlugins = 
true;
 
  459   catch(
const std::exception& e)
 
  465     QString msgErr(tr(
"Error reading application's plugin list: %1"));
 
  467     msgErr = msgErr.arg(e.what());
 
  469     QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
 
  483   catch(
const std::exception& e)
 
  489     QString msgErr(tr(
"Some plugins couldn't be loaded. %1\n\n" 
  490                       "Please, refer to plugin manager to fix the problem."));
 
  492     msgErr = msgErr.arg(e.what());
 
  494     QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
 
  514     std::string projPath, projTitle;
 
  516     bool hasProjects = p.count(
"MostRecentProject") > 0;
 
  520       projPath = p.get<std::string>(
"MostRecentProject.<xmlattr>.xlink:href");
 
  521       projTitle = p.get<std::string>(
"MostRecentProject.<xmlattr>.title");
 
  524     QMenu* mnu = getMenu(
"File.Recent Projects");
 
  526     if(!projPath.empty())
 
  528       QString pp = projPath.c_str();
 
  529       QAction* act = mnu->addAction(pp);
 
  534       m_recentProjs.append(pp);
 
  535       m_recentProjsTitles.append(projTitle.c_str());
 
  538     hasProjects = p.count(
"RecentProjects") > 0;
 
  542       BOOST_FOREACH(boost::property_tree::ptree::value_type& v, p.get_child(
"RecentProjects"))
 
  544         QString pp = v.second.get<std::string>(
"<xmlattr>.xlink:href").c_str();
 
  545         QString pt = v.second.get<std::string>(
"<xmlattr>.title").c_str();
 
  546         QAction* act = mnu->addAction(pp);
 
  548         m_recentProjs.append(pp);
 
  549         m_recentProjsTitles.append(pt);
 
  555   catch(
const std::exception& e)
 
  559     QString msgErr(tr(
"Error loading the registered projects: %1"));
 
  561     msgErr = msgErr.arg(e.what());
 
  563     QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
 
  569   int pos = m_recentProjs.indexOf(prjFile);
 
  580       if(m_recentProjs.size() >= maxSaved) 
 
  582         m_recentProjs.removeLast();
 
  583         m_recentProjsTitles.removeLast();
 
  586       m_recentProjs.prepend(prjFile);
 
  587       m_recentProjsTitles.prepend(prjTitle);
 
  591       m_recentProjs.move(pos, 0);
 
  592       m_recentProjsTitles.move(pos, 0);
 
  595     QMenu* mnu = getMenu(
"File.Recent Projects");
 
  599     QString recPrj = m_recentProjs.at(0);
 
  600     QAction* act = mnu->addAction(recPrj);
 
  601     act->setData(recPrj);
 
  605     if(m_recentProjs.size() > 1)
 
  606       for(
int i=1; i<m_recentProjs.size(); i++)
 
  608         recPrj = m_recentProjs.at(i);
 
  609         act = mnu->addAction(recPrj);
 
  610         act->setData(recPrj);
 
  614   QAction* act = findAction(
"File.Save Project As");
 
  617     act->setEnabled(
true);
 
  647   m_appConfigFile.clear();
 
  649   m_initialized = 
false;
 
  654   return m_appSettings;
 
  672   return m_appIconName;
 
  677   return m_recentProjs.isEmpty() ? QString(
"") : m_recentProjs.front();
 
  682   return m_defaultSRID;
 
  687   return m_selectionColor;
 
  692   return m_msgBoxParentWidget;
 
void load()
It starts all the plugins enabled by the user. 
 
virtual void initializePlugins()
Load the plugin list and initialize the plugins enabled by the user. 
 
void registerMenu(QMenu *mnu)
Register the mnu. 
 
QMenu * findMenu(const QString &id) const 
Returns the menu registered with key id. 
 
A singleton for holding he application splash screen. 
 
void registerMenuBar(QMenuBar *bar)
Register the bar. 
 
QColor getSelectionColor() const 
Returns the application selection color. 
 
#define TERRALIB_APPLICATION_CONFIG_FILE
The file that contains the application plugins. 
 
void finalize()
It finalizes the TerraLib Platform. 
 
Utility routines for the TerraLib Application Framework module. 
 
The base API for controllers of TerraLib applications. 
 
const boost::property_tree::ptree & getAllSettings() const 
It return a reading reference to the internal settings. 
 
const QString & getAppTitle() const 
Returns the application title. 
 
std::string getValue(const std::string &key)
It returns the value for a given key or empty. 
 
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib. 
 
static ApplicationController * sm_instance
There can be only one object of class Application. 
 
The base API for TerraLib applications. 
 
static ApplicationController & getInstance()
It gives access to the controller singleton. 
 
void registerToolBar(const QString &id, QToolBar *bar)
Register the toolbar in the list of the known toolbars. 
 
void removeToolBar(const QString &id)
Removes the toolbar identified by id. 
 
int getDefaultSRID() const 
Returns the application default SRID value. 
 
TEQTWIDGETSEXPORT QAction * FindAction(const QString &actText, QMenu *mnu)
 
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
 
QSettings & getSettings()
Return the QSettings of the application. This can be used to add settings from external sources...
 
TEQTAFEXPORT void SaveDataSourcesFile()
Saves data sources file. 
 
This class models the concept of a project for the TerraLib Application Framework. 
 
void removeListener(QObject *obj)
Remove the obj from the list of event listeners. 
 
void showMessage(const QString &message)
This will cause the text to be drawn on the splash screen and a call to Application::processEvents() ...
 
void addToolBar(const QString &id, QToolBar *bar)
Register the toolbar in the list of the known toolbars and dispatch an event. 
 
A singleton for managing the application plugins. 
 
A singleton for managing the plugins enabled by a specific user. 
 
ApplicationController()
Constructor. 
 
QString getMostRecentProject() const 
Returns the most recent project. 
 
virtual ~ApplicationController()
Destructor. 
 
virtual void setConfigFile(const std::string &configFileName)
Tells wich configuration file to be used by the controller during its initialization. 
 
virtual void setMsgBoxParentWidget(QWidget *w)
Tells the widget to be used as the parent of messages showned in a QMessageBox. 
 
void set(te::qt::af::Project *prj)
Set the current project. 
 
TEQTAFEXPORT void UpdateUserSettings(const QStringList &prjFiles, const QStringList &prjTitles, const std::string &userConfigFile)
Updates user settings file section about information of the projects. 
 
std::vector< QToolBar * > getToolBars() const 
Return the list of registered toolbars. 
 
TEQTWIDGETSEXPORT QMenu * GetMenu(const QString &mnuText, QMenu *mnu)
Gets a menu or submenu contained in the mnu object. 
 
This event signals that a new toolbar was added. 
 
virtual void initialize()
Initializes the application framework. 
 
virtual void finalize()
Finalize the application framework. 
 
TEQTAFEXPORT void CreateDefaultSettings()
Creates a default QSettings. 
 
void addListener(QObject *obj)
Insert an application item that will listen to framework events. 
 
virtual void initializeProjectMenus()
Initializes the menus for the most recent open projects. 
 
A base class for application events. 
 
#define TR_QT_AF(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
 
A help manager that uses the QAssistant to manage help files. 
 
static SplashScreenManager & getInstance()
It returns a reference to the singleton instance. 
 
QToolBar * getToolBar(const QString &id) const 
Return the toolbar identified by id or NULL if none is found. 
 
void load()
It tries to find a default config file based on system macros and default condigurations. 
 
This class models the concept of a project for the TerraLib Application Framework. 
 
void updateRecentProjects(const QString &prjFile, const QString &prjTitle)
Update the list of recent projects. This is commonly used when there's a new most recent project...
 
QWidget * getMainWindow() const 
Returns main window. 
 
TEQTAFEXPORT void UpdateApplicationPlugins()
Update plugins file. 
 
QMenuBar * findMenuBar(const QString &id) const 
Returns the menu bar registered with key id. 
 
QMenuBar * getMenuBar(const QString &id) const 
Returns a menu bar registered with key id. 
 
void broadcast(te::qt::af::evt::Event *evt)
Send events in broadcast for all registered components. 
 
Contains the list of the application events. 
 
void initialize()
It initializes the TerraLib Platform. 
 
QAction * findAction(const QString &id) const 
Returns the action identified by id or NULL if there's not an action identified by id...
 
te::qt::af::Project * getProject()
Get the current project. 
 
TEQTAFEXPORT void GetProjectInformationsFromSettings(QString &defaultAuthor, int &maxSaved)
 
TEDATAACCESSEXPORT void ReadDataSourceInfo(const std::string &datasourcesFileName)
 
const QString & getAppIconName() const 
Returns the application icon. 
 
void close()
Closes the splash screen. 
 
An object that when created shows a cursor during its scope. 
 
TEQTWIDGETSEXPORT QMenu * FindMenu(const QString &mnuText, QMenu *mnu)
Finds a menu item in the mnu object. 
 
QMenu * getMenu(const QString &id)
Returns a menu registered with key id.