27 #include <boost/foreach.hpp>
30 #include "../../common/Exception.h"
31 #include "../../common/PlatformUtils.h"
32 #include "../../common/Translator.h"
33 #include "../../common/TerraLib.h"
34 #include "../../common/SystemApplicationSettings.h"
35 #include "../../common/UserApplicationSettings.h"
36 #include "../../common/Logger.h"
37 #include "../../common/Version.h"
38 #include "../../dataaccess/serialization/xml/Serializer.h"
39 #include "../../plugin/PluginManager.h"
40 #include "../../plugin/PluginInfo.h"
41 #include "../../plugin/Utils.h"
42 #include "../../srs/Config.h"
43 #include "../widgets/help/AssistantHelpManagerImpl.h"
44 #include "../widgets/help/HelpManager.h"
45 #include "../widgets/Utils.h"
46 #include "../widgets/utils/ScopedCursor.h"
56 #include <QApplication>
57 #if QT_VERSION < 0x050000
58 #include <QDesktopServices>
63 #include <QMessageBox>
65 #if QT_VERSION >= 0x050000
66 #include <QStandardPaths>
71 #include <boost/filesystem.hpp>
73 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
75 #include <log4cxx/basicconfigurator.h>
76 #include <log4cxx/consoleappender.h>
77 #include <log4cxx/fileappender.h>
78 #include <log4cxx/helpers/pool.h>
79 #include <log4cxx/helpers/transcoder.h>
80 #include <log4cxx/logger.h>
81 #include <log4cxx/logmanager.h>
82 #include <log4cxx/logstring.h>
83 #include <log4cxx/simplelayout.h>
90 m_msgBoxParentWidget(0),
92 m_selectionColor(QColor(0, 255, 0)),
106 m_appConfigFile = configFileName;
111 m_msgBoxParentWidget = w;
116 registerToolBar(
id, bar);
126 QToolBar* b = getToolBar(
id);
129 throw Exception(
TE_TR(
"There is already a tool bar registered with the same name!"));
131 m_toolbars[id] = bar;
136 std::map<QString, QToolBar*>::const_iterator it = m_toolbars.find(
id);
138 return (it != m_toolbars.end()) ? it->second : 0;
143 std::vector<QToolBar*> res;
144 std::map<QString, QToolBar*>::const_iterator it;
146 for(it = m_toolbars.begin(); it != m_toolbars.end(); ++it)
147 res.push_back(it->second);
154 std::map<QString, QToolBar*>::iterator it = m_toolbars.find(
id);
156 if(it != m_toolbars.end())
157 m_toolbars.erase(it);
162 m_menus.push_back(mnu);
167 std::vector<QMenu*>::const_iterator it;
170 for(it = m_menus.begin(); it != m_menus.end(); ++it)
179 std::vector<QMenuBar*>::const_iterator it_bar;
181 for(it_bar = m_menuBars.begin(); it_bar != m_menuBars.end(); ++it_bar)
194 QMenu* mnu = findMenu(
id);
198 if(!m_menuBars.empty())
203 m_menus.push_back(mnu);
212 m_menuBars.push_back(bar);
217 throw Exception(
"Not implemented yet.");
222 return m_menuBars[0];
227 for(
size_t i=0; i<m_menus.size(); i++)
235 for(
size_t i=0; i<m_menuBars.size(); i++)
248 std::set<QObject*>::const_iterator it = m_applicationItems.find(obj);
250 if(it != m_applicationItems.end())
253 m_applicationItems.insert(obj);
260 std::set<QObject*>::iterator it = m_applicationItems.find(obj);
262 if(it == m_applicationItems.end())
265 m_applicationItems.erase(it);
276 #if QT_VERSION >= 0x050000
277 m_userDataDir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
279 m_userDataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
282 if(!boost::filesystem::exists(m_userDataDir.toStdString()))
283 boost::filesystem::create_directories(m_userDataDir.toStdString());
290 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
291 std::string path = m_userDataDir.toStdString();
292 path +=
"/log/terralib.log";
294 log4cxx::FileAppender* fileAppender =
new log4cxx::FileAppender(log4cxx::LayoutPtr(
new log4cxx::SimpleLayout()),
297 log4cxx::helpers::Pool p;
298 fileAppender->activateOptions(p);
300 log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(fileAppender));
301 log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getAll() );
302 log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(
"te");
322 if(!boost::filesystem::exists(m_appIconName.toStdString()))
327 if(!boost::filesystem::exists(m_aboutLogo.toStdString()))
332 if(!boost::filesystem::exists(m_tLibLogo.toStdString()))
336 qApp->setApplicationName(fullAppName);
340 qApp->setOrganizationName(m_appOrganization);
347 m_appHelpFile = QString::fromStdString(help_file);
349 QFileInfo info(m_appHelpFile);
351 if(!m_appHelpFile.isEmpty() && info.exists())
362 catch(
const std::exception& e)
366 QString msgErr(tr(
"Error loading application help system: %1"));
368 msgErr = msgErr.arg(e.what());
370 QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
374 QSettings user_settings(QSettings::IniFormat,
375 QSettings::UserScope,
376 QApplication::instance()->organizationName(),
377 QApplication::instance()->applicationName());
386 m_appIconThemeDir = QString::fromStdString(icon_dir);
388 if(!m_appIconThemeDir.isEmpty())
390 QStringList ithemes = QIcon::themeSearchPaths();
392 ithemes.push_back(m_appIconThemeDir);
394 QIcon::setThemeSearchPaths(ithemes);
399 QVariant iconTheme = user_settings.value(
"icon_theme/selected_theme", m_appDefaultIconTheme);
401 QIcon::setThemeName(iconTheme.toString());
406 QString sh = QString(
"QToolBar { qproperty-iconSize: ") + iconSize.toString() +
"px " + iconSize.toString() +
"px; }";
407 qApp->setStyleSheet(sh);
413 m_defaultSRID = srid.toInt();
418 m_selectionColor = QColor(selectionColor.toString());
422 catch(
const std::exception& e)
426 QString msgErr(tr(
"Error loading application icon theme: %1"));
428 msgErr = msgErr.arg(e.what());
430 QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
436 m_appDatasourcesFile = user_settings.value(
"data_sources/data_file",
"").toString().toStdString();
438 if(!m_appDatasourcesFile.empty())
449 catch(
const std::exception& e)
453 QString msgErr(tr(
"Error loading the registered data sources: %1"));
455 msgErr = msgErr.arg(e.what());
457 QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
460 QFileInfo info(user_settings.fileName());
465 m_initialized =
true;
472 std::vector<std::string> plgFiles;
484 QSettings user_settings(QSettings::IniFormat,
485 QSettings::UserScope,
486 QApplication::instance()->organizationName(),
487 QApplication::instance()->applicationName());
489 user_settings.beginGroup(
"plugins");
491 std::set<std::string> user_enabled_plugins;
493 int nitems = user_settings.beginReadArray(
"enabled");
495 for(
int i = 0; i != nitems; ++i)
497 user_settings.setArrayIndex(i);
499 QString name = user_settings.value(
"name").toString();
501 user_enabled_plugins.insert(name.toStdString());
504 user_settings.endArray();
506 user_settings.endGroup();
513 boost::ptr_vector<te::plugin::PluginInfo> plugins;
515 for(std::size_t i = 0; i != plgFiles.size(); ++i)
519 if(user_enabled_plugins.empty())
520 plugins.push_back(pinfo);
521 else if(user_enabled_plugins.count(pinfo->
m_name) != 0)
522 plugins.push_back(pinfo);
532 catch(
const std::exception& e)
536 QString msgErr(tr(
"Error reading application's plugin list: %1"));
538 msgErr = msgErr.arg(e.what());
540 QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
550 QSettings user_settings(QSettings::IniFormat,
551 QSettings::UserScope,
552 QApplication::instance()->organizationName(),
553 QApplication::instance()->applicationName());
555 QVariant projPath = user_settings.value(
"projects/most_recent/path",
"");
556 QVariant projTitle = user_settings.value(
"projects/most_recent/title",
"");
558 QMenu* mnu = getMenu(
"File.Recent Projects");
560 if(!projPath.toString().isEmpty())
562 QAction* act = mnu->addAction(projPath.toString());
563 act->setData(projPath);
567 m_recentProjs.append(projPath.toString());
568 m_recentProjsTitles.append(projTitle.toString());
571 user_settings.beginGroup(
"projects");
573 int nrc = user_settings.beginReadArray(
"recents");
575 for(
int i = 0; i != nrc; ++i)
577 user_settings.setArrayIndex(i);
578 QString npath = user_settings.value(
"projects/path").toString();
579 QString ntitle = user_settings.value(
"projects/title").toString();
582 QAction* act = mnu->addAction(npath);
584 m_recentProjs.append(npath);
585 m_recentProjsTitles.append(ntitle);
588 mnu->setEnabled(
true);
592 catch(
const std::exception& e)
596 QString msgErr(tr(
"Error loading the registered projects: %1"));
598 msgErr = msgErr.arg(e.what());
600 QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
606 int pos = m_recentProjs.indexOf(prjFile);
617 if(m_recentProjs.size() > maxSaved)
619 m_recentProjs.removeLast();
620 m_recentProjsTitles.removeLast();
623 m_recentProjs.prepend(prjFile);
624 m_recentProjsTitles.prepend(prjTitle);
628 m_recentProjs.move(pos, 0);
629 m_recentProjsTitles.move(pos, 0);
632 if(m_recentProjs.isEmpty())
635 QMenu* mnu = getMenu(
"File.Recent Projects");
639 mnu->setEnabled(
true);
641 QString recPrj = m_recentProjs.at(0);
642 QAction* act = mnu->addAction(recPrj);
643 act->setData(recPrj);
647 if(m_recentProjs.size() > 1)
648 for(
int i=1; i<m_recentProjs.size(); i++)
650 recPrj = m_recentProjs.at(i);
651 act = mnu->addAction(recPrj);
652 act->setData(recPrj);
656 QAction* act = findAction(
"File.Save Project As");
659 act->setEnabled(
true);
690 m_appConfigFile.clear();
692 m_applicationItems.clear();
702 m_appDatasourcesFile.clear();
704 m_appDefaultIconTheme.clear();
706 m_appHelpFile.clear();
708 m_appIconName.clear();
710 m_appIconThemeDir.clear();
714 m_msgBoxParentWidget = 0;
716 m_appOrganization.clear();
722 m_recentProjs.clear();
724 m_recentProjsTitles.clear();
726 m_appUserSettingsFile.clear();
728 m_appPluginsFile.clear();
730 m_appToolBarDefaultIconSize.clear();
734 m_selectionColor = QColor();
738 m_initialized =
false;
743 return m_appSettings;
761 return m_appIconName;
776 return m_recentProjs.isEmpty() ? QString(
"") : m_recentProjs.front();
781 return m_defaultSRID;
786 return m_selectionColor;
791 m_selectionColor = c;
796 return m_msgBoxParentWidget;
801 m_resetTerralib = status;
806 return m_userDataDir;
TEQTAFEXPORT std::vector< std::string > GetPluginsFiles()
virtual void setConfigFile(const std::string &configFileName)
It gives access to the controller singleton.
void registerMenu(QMenu *mnu)
Register the mnu.
std::string m_name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
virtual ~ApplicationController()
Destructor.
TEQTAFEXPORT void CreateDefaultSettings()
Creates a default QSettings.
virtual void initializePlugins()
Load the plugin list and initialize the plugins enabled by the user.
const QString & getAppTitle() const
Returns the application title.
TECOMMONEXPORT std::string FindInTerraLibPath(const std::string &p)
Returns the path relative to a directory or file in the context of TerraLib.
QMenu * getMenu(const QString &id)
Returns a menu registered with key id.
A base class for application events.
QWidget * getMainWindow() const
Returns main window.
void registerMenuBar(QMenuBar *bar)
Register the bar.
const QString & getAppIconName() const
Returns the application icon.
static std::string asString()
ApplicationController()
Constructor.
This class models the concept of a project for the TerraLib Application Framework.
void setResetTerraLibFlag(const bool &status)
A singleton for holding he application splash screen.
void set(te::qt::af::Project *prj)
Set the current project.
QMenuBar * getMenuBar(const QString &id) const
Returns a menu bar registered with key id.
const QString & getUserDataDir() const
#define TE_TR(message)
It marks a string in order to get translated.
TEQTAFEXPORT void UpdateUserSettings(const QStringList &prjFiles, const QStringList &prjTitles, const std::string &userConfigFile)
Updates user settings file section about information of the projects.
void showMessage(const QString &message)
This will cause the text to be drawn on the splash screen and a call to Application::processEvents() ...
TEQTAFEXPORT void SaveDataSourcesFile()
Saves data sources file.
QToolBar * getToolBar(const QString &id) const
Return the toolbar identified by id or NULL if none is found.
virtual void initialize()
Initializes the application framework.
QMenu * findMenu(const QString &id) const
Returns the menu registered with key id.
QColor getSelectionColor() const
Returns the application selection color.
void finalize()
It finalizes the TerraLib Platform.
static SplashScreenManager & getInstance()
It returns a reference to the singleton instance.
void removeToolBar(const QString &id)
Removes the toolbar identified by id.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
void addListener(QObject *obj)
Insert an application item that will listen to framework events.
TEQTAFEXPORT void GetProjectInformationsFromSettings(QString &defaultAuthor, int &maxSaved)
virtual void setMsgBoxParentWidget(QWidget *w)
Tells the widget to be used as the parent of messages showned in a QMessageBox.
virtual void initializeProjectMenus()
Initializes the menus for the most recent open projects.
Utility functions for dealing with plugins.
void addToolBar(const QString &id, QToolBar *bar)
Register the toolbar in the list of the known toolbars and dispatch an event.
void initialize()
It initializes the TerraLib Platform.
QSettings & getSettings()
Return the QSettings of the application. This can be used to add settings from external sources...
void broadcast(te::qt::af::evt::Event *evt)
Send events in broadcast for all registered components.
bool decode(std::string &s)
Decode the pct-encoded (hex) sequences, if any, return success.
void setSelectionColor(const QColor &c)
Sets the application selection color.
te::qt::af::Project * getProject()
Get the current project.
QMenuBar * findMenuBar(const QString &id) const
Returns the menu bar registered with key id.
This class models the concept of a project for the TerraLib Application Framework.
QAction * findAction(const QString &id) const
Returns the action identified by id or NULL if there's not an action identified by id...
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void removeListener(QObject *obj)
Remove the obj from the list of event listeners.
std::vector< QToolBar * > getToolBars() const
Return the list of registered toolbars.
const QString & getTlibLogo() const
The basic information about a plugin.
QString getMostRecentProject() const
Returns the most recent project.
Contains the list of the application events.
TEPLUGINEXPORT PluginInfo * GetInstalledPlugin(const std::string &pluginFilePath)
It returns information about a given plugin provided its plugin configuration file name or dir...
The base API for controllers of TerraLib applications.
void registerToolBar(const QString &id, QToolBar *bar)
Register the toolbar in the list of the known toolbars.
virtual void finalize()
Finalize the application framework.
TEDATAACCESSEXPORT void ReadDataSourceInfo(const std::string &datasourcesFileName)
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...
int getDefaultSRID() const
Returns the application default SRID value.
const QString & getAboutLogo() const