29 #include "../../common/Exception.h" 30 #include "../../common/TerraLib.h" 31 #include "../../common/SystemApplicationSettings.h" 32 #include "../../common/UserApplicationSettings.h" 33 #include "../../common/Version.h" 34 #include "../../core/logger/Logger.h" 35 #include "../../core/plugin.h" 36 #include "../../core/translator/Translator.h" 37 #include "../../core/utils/Platform.h" 38 #include "../../dataaccess/serialization/xml/Serializer.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" 53 #include <QApplication> 54 #if QT_VERSION < 0x050000 55 #include <QDesktopServices> 60 #include <QMessageBox> 62 #if QT_VERSION >= 0x050000 63 #include <QStandardPaths> 65 #include <QLibraryInfo> 66 #include <QTranslator> 70 #include <boost/filesystem.hpp> 71 #include <boost/algorithm/string/join.hpp> 72 #include <boost/format.hpp> 79 std::vector<std::string> res;
83 for(boost::property_tree::ptree::value_type &v : doc.get_child(
"Application.PluginsDirectoriesInfo"))
84 res.push_back(v.second.data());
94 : m_msgBoxParentWidget(nullptr),
96 m_selectionColor(QColor(0, 255, 0)),
129 throw Exception(
TE_TR(
"There is already a tool bar registered with the same name!"));
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;
147 res.push_back(it->second);
154 std::map<QString, QToolBar*>::iterator it =
m_toolbars.find(
id);
167 std::vector<QMenu*>::const_iterator it;
179 std::vector<QMenuBar*>::const_iterator it_bar;
216 const QString& )
const 222 const QString& )
const 229 for(
size_t i=0; i<
m_menus.size(); i++)
250 for(
size_t i=0; i<
m_menus.size(); i++)
254 if (actGroup !=
nullptr)
262 if (actGroup !=
nullptr)
303 m_appVersion = QApplication::instance()->applicationVersion();
325 qApp->setApplicationName(fullAppName);
332 #if QT_VERSION >= 0x050000 333 m_userDataDir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
335 m_userDataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
346 #ifdef TERRALIB_LOGGER_ENABLED 348 logfile +=
"/log/TerraLib.log";
372 catch(
const std::exception& e)
376 QString msgErr(tr(
"Error loading application help system: %1"));
378 msgErr = msgErr.arg(e.what());
384 QSettings user_settings(QSettings::IniFormat,
385 QSettings::UserScope,
386 QApplication::instance()->organizationName(),
387 QApplication::instance()->applicationName());
400 QStringList ithemes = QIcon::themeSearchPaths();
404 QIcon::setThemeSearchPaths(ithemes);
411 QIcon::setThemeName(iconTheme.toString());
416 QString sh = QString(
"QToolBar { qproperty-iconSize: ") + iconSize.toString() +
"px " + iconSize.toString() +
"px; }";
417 qApp->setStyleSheet(sh);
432 catch(
const std::exception& e)
436 QString msgErr(tr(
"Error loading application icon theme: %1"));
438 msgErr = msgErr.arg(e.what());
446 m_appDatasourcesFile = user_settings.value(
"data_sources/data_file",
"").toString().toUtf8().data();
464 QFileInfo infoDataSourceFile(fileName.toString());
467 if (infoDataSourceFile.exists())
471 reply = QMessageBox::question(
nullptr, tr(
"Data Sources XML"), tr(
"A file containing data sources already configured was found. Would you like to load it."), QMessageBox::No, QMessageBox::Yes);
475 if (reply == QMessageBox::Yes)
477 std::string dataSourcesFile = fileName.toString().toUtf8().data();
488 if (!infoDataSourceFile.exists() || reply == QMessageBox::No)
492 if (!lastFormerVersionPath.empty())
496 QFileInfo infoDataSourceFile(fileName.toString());
498 if (infoDataSourceFile.exists())
502 boost::filesystem::path formerPath(lastFormerVersionPath);
503 std::string appName = formerPath.filename().string();
505 QString q(tr(
"A ") + QString::fromUtf8(appName.c_str()));
506 q.append(tr(
" file containing data sources was found.\n"));
507 q.append(tr(
"Would you like to load it?"));
509 reply = QMessageBox::question(
nullptr, tr(
"Data Sources XML"), q, QMessageBox::No, QMessageBox::Yes);
513 if (reply == QMessageBox::Yes)
515 std::string dataSourcesFile = fileName.toString().toUtf8().data();
528 catch(
const std::exception& e)
532 QString msgErr(tr(
"Error loading the registered data sources: %1"));
534 msgErr = msgErr.arg(e.what());
546 QSettings user_settings(QSettings::IniFormat, QSettings::UserScope,
547 QApplication::instance()->organizationName(),
548 QApplication::instance()->applicationName());
551 tr(
"Loading plugins..."));
553 user_settings.beginGroup(
"plugins");
555 std::set<std::string> user_loaded_plugins;
557 int nLoaded = user_settings.beginReadArray(
"loaded");
559 for(
int i = 0; i != nLoaded; ++i)
561 user_settings.setArrayIndex(i);
563 QString name = user_settings.value(
"name").toString();
565 user_loaded_plugins.insert(name.toUtf8().data());
568 user_settings.endArray();
571 std::set<std::string> user_unloaded_plugins;
572 int nUnloaded = user_settings.beginReadArray(
"unloaded");
574 for(
int i = 0; i != nUnloaded; ++i)
576 user_settings.setArrayIndex(i);
578 QString name = user_settings.value(
"name").toString();
580 user_unloaded_plugins.insert(name.toUtf8().data());
583 user_settings.endArray();
585 user_settings.endGroup();
587 if(user_loaded_plugins.size() > 0 || user_unloaded_plugins.size() > 0)
591 std::vector<std::string> failToLoad;
598 if(user_loaded_plugins.find(pinfo.name) != user_loaded_plugins.end())
603 failToLoad.push_back(pinfo.name);
606 if(failToLoad.size() > 0)
610 boost::format err_msg(
611 tr(
"Could not load the following plugins:\n\n%1%")
617 (err_msg % boost::algorithm::join(failToLoad,
"\n")).str().c_str());
618 msg.setWindowFlags(Qt::WindowStaysOnTopHint);
624 tr(
"Plugins loaded successfully!"));
636 tr(
"Plugins loaded successfully!"));
642 if(
const std::string*
d = boost::get_error_info<te::ErrorDescription>(e))
646 msg.setWindowFlags(Qt::WindowStaysOnTopHint);
652 QMessageBox::Warning,
m_appTitle,
"An unknown error has occurred");
653 msg.setWindowFlags(Qt::WindowStaysOnTopHint);
657 catch(
const std::exception& e)
661 QString msgErr(tr(
"Error reading application's plugin list: %1"));
663 msgErr = msgErr.arg(e.what());
667 msg.setWindowFlags(Qt::WindowStaysOnTopHint);
826 sysSettings->
load(configFileName.toStdString());
828 appName = sysSettings->
getValue(
"Application.Name");
829 appTitle = sysSettings->
getValue(
"Application.Title");
830 appIconName = sysSettings->
getValue(
"Application.IconName");
831 aboutLogo = sysSettings->
getValue(
"Application.AboutDialogLogo.<xmlattr>.xlink:href");
832 tLibLogo = sysSettings->
getValue(
"Application.TerraLibLogo.<xmlattr>.xlink:href");
835 appDefaultIconTheme = sysSettings->
getValue(
"Application.IconThemeInfo.DefaultTheme");
836 appOrganization = sysSettings->
getValue(
"Application.Organization");
839 qApp->setApplicationName(QString::fromStdString(fullAppName));
840 qApp->setOrganizationName(QString::fromStdString(appOrganization));
842 #if QT_VERSION >= 0x050000 843 userDataDir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
845 userDataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
848 QSettings userSettings(QSettings::IniFormat,
849 QSettings::UserScope,
850 qApp->organizationName(),
851 qApp->applicationName());
854 auto userDataDirS = userDataDir.toStdString();
860 appIconSize = userSettings.value(
"toolbars/icon_size", QString::fromStdString(sysSettings->
getValue(
"Application.ToolBarDefaultIconSize"))).toString();
861 appIconThemeName = userSettings.value(
"icon_theme/selected_theme", QString::fromStdString(appDefaultIconTheme)).toString();
863 QStringList nIthemes;
865 if(!appIconThemeDir.empty())
867 auto tDir = QString::fromStdString(appIconThemeDir);
871 nIthemes <<QIcon::themeSearchPaths();
873 QIcon::setThemeSearchPaths(nIthemes);
874 QIcon::setThemeName(QString::fromStdString(appIconName));
885 QString iSize = userSettings.value(
"toolbars/icon_size", QString::fromStdString(sysSettings->
getValue(
"Application.ToolBarDefaultIconSize"))).toString();
887 QString sh = QString(
"QToolBar { qproperty-iconSize: ") + iSize +
"px " + iSize +
"px; }";
888 qApp->setStyleSheet(sh);
894 QDir dir(QLibraryInfo::location(QLibraryInfo::TranslationsPath));
896 filters <<
"*" + QLocale::system().name().toLower() +
".qm";
898 lst = dir.entryInfoList(filters, QDir::Files);
900 for(
int i=0; i<lst.size(); ++i)
902 QTranslator* trans =
new QTranslator;
903 trans->load(lst.at(i).baseName(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
904 qApp->installTranslator(trans);
907 QPixmap pixmap(splashFileName);
908 QSplashScreen* splash =
new QSplashScreen(pixmap);
910 splash->setStyleSheet(
"QWidget { font-size: 12px; font-weight: bold }");
std::string m_appUserSettingsFile
Name of the user settings file.
virtual void setConfigFile(const std::string &configFileName)
Tells wich configuration file to be used by the controller during its initialization.
TECOREEXPORT std::vector< PluginInfo > PluginFinder(const std::vector< std::string > &dirs)
QActionGroup * findActionGroup(const QString &id) const
Returns the action group identified by id or NULL if there's not an action group identified by id...
void registerMenu(QMenu *mnu)
Register the mnu.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
virtual ~ApplicationController()
Destructor.
TECOREEXPORT std::vector< PluginInfo > TopologicalSort(const std::vector< PluginInfo > &v_pinfo)
static bool createDirectories(const std::string &path)
Creates a directory for any element of path that does not exist.
std::set< QObject * > m_applicationItems
The list of registered application items.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
QString m_appIconName
Icon used in the application.
virtual void initializePlugins()
Load the plugin list and initialize the plugins enabled by the user.
const QString & getAppTitle() const
Returns the application title.
static void prepareQtEnvironment(const QString &configFileName, const QString &splashFileName)
Base exception class for plugin module.
QMenu * getMenu(const QString &id)
Returns a menu registered with key id.
void insert(const PluginInfo &pinfo)
Adds plugin with its plugin information to the list of unloaded plugins.
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.
QColor m_selectionColor
Default selection color.
static std::string asString()
ApplicationController()
Constructor.
void setResetTerraLibFlag(const bool &status)
A singleton for holding he application splash screen.
Basic information about a plugin.
QMenuBar * getMenuBar(const QString &id) const
Returns a menu bar registered with key id.
std::map< QString, QToolBar * > m_toolbars
Toolbars registered.
const QString & getUserDataDir() const
#define TE_TR(message)
It marks a string in order to get translated.
void load(const std::string &plugin_name, const bool start=true)
It tries to load the informed plugin.
QString m_appPluginsPath
Name of the plugins path.
virtual void finalizePlugins()
QString m_appTitle
Application title.
static Logger & instance()
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.
virtual void initialize()
Initializes the application framework.
const QString & getAppName() const
Returns the application name.
static PluginManager & instance()
Access the singleton.
QMenu * findMenu(const QString &id) const
Returns the menu registered with key id.
QColor getSelectionColor() const
Returns the application selection color.
std::vector< QMenu * > m_menus
Menus registered.
const QString & getAppPluginsPath() const
Returns the plugins file path of application.
void finalize()
It finalizes the TerraLib Platform.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
QWidget * m_msgBoxParentWidget
Parent used to show message boxes.
void removeToolBar(const QString &id)
Removes the toolbar identified by id.
A singleton for managing application settings applied to the whole system (all users).
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
TECOREEXPORT void LoadAll(bool start=true)
virtual void setMsgBoxParentWidget(QWidget *w)
Tells the widget to be used as the parent of messages showned in a QMessageBox.
std::string m_appConfigFile
The application framework configuration file.
const QString & getAppVersion() const
Returns the application version.
#define TE_INIT_DEFAULT_LOGGER(filename)
Use this tag in order to initialize the default TerraLib logger.
QString m_appHelpFile
Name of the help file.
QString m_appVersion
The application version.
void removeAllLoggers()
It removes all added loggers.
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.
void addListener(QObject *obj, const ListenerType &type=BOTH)
Insert an application item that will listen to framework events.
#define TERRALIB_APPLICATION_DATASOURCE_FILE_NAME
The default name for the application file containing the list of data sources.
QSettings & getSettings()
Return the QSettings of the application. This can be used to add settings from external sources...
std::string m_appDatasourcesFile
Name of the file containing datasources used.
QString m_appToolBarDefaultIconSize
Size of the tool buttons.
Utility routines for the TerraLib Application Framework module.
void setSelectionColor(const QColor &c)
Sets the application selection color.
QMenuBar * findMenuBar(const QString &id) const
Returns the menu bar registered with key id.
void trigger(te::qt::af::evt::Event *)
int m_defaultSRID
Default SRID value.
QAction * findAction(const QString &id) const
Returns the action identified by id or NULL if there's not an action identified by id...
QString m_appIconThemeDir
Directory of the application icon theme.
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
TEQTAFEXPORT std::string GetLastFormerVersionPath(te::qt::af::ApplicationController *appController)
void removeListener(QObject *obj)
Remove the obj from the list of event listeners.
std::vector< QToolBar * > getToolBars() const
Return the list of registered toolbars.
void triggered(te::qt::af::evt::Event *)
Send events in broadcast for all registered components.
const QString & getTlibLogo() const
QString m_appDefaultIconTheme
Name of the icon theme to be used.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::string getValue(const std::string &key)
It returns the value for a given key or empty.
void load(const std::string &fileName)
It tries to find a default config file based on system macros and default condigurations.
void clear()
Stop and unload all plugins, then clear the internal list of plugins.
std::vector< std::string > GetPluginsDirectories(boost::property_tree::ptree doc)
std::vector< QMenuBar * > m_menuBars
Menu bars registered.
QString m_appOrganization
Organization name.
bool m_initialized
A flag indicating if the controller is initialized.
Base exception class for TerraLib Core Runtime Library.
QString m_appName
Application name.
Contains the list of the application events.
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)
int getDefaultSRID() const
Returns the most recent project.
const QString & getAboutLogo() const
Returns the application project extension.
QString m_userDataDir
The data dir used to store data files.