ApplicationController.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/af/ApplicationController.cpp
22 
23  \brief The base API for controllers of TerraLib applications.
24 */
25 
26 // Boost
27 
28 // TerraLib
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"
45 #include "ApplicationController.h"
46 #include "Exception.h"
47 //#include "Project.h"
48 #include "SplashScreenManager.h"
49 #include "Utils.h"
50 #include "XMLFormatter.h"
51 
52 // Qt
53 #include <QApplication>
54 #if QT_VERSION < 0x050000
55 #include <QDesktopServices>
56 #endif
57 #include <QDir>
58 #include <QIcon>
59 #include <QMenu>
60 #include <QMessageBox>
61 #include <QResource>
62 #if QT_VERSION >= 0x050000
63 #include <QStandardPaths>
64 #endif
65 #include <QLibraryInfo>
66 #include <QTranslator>
67 #include <QWidget>
68 
69 // Boost
70 #include <boost/filesystem.hpp>
71 #include <boost/algorithm/string/join.hpp>
72 #include <boost/format.hpp>
73 
74 //STL
75 #include <algorithm>
76 
77 std::vector<std::string> GetPluginsDirectories(boost::property_tree::ptree doc)
78 {
79  std::vector<std::string> res;
80 
81  try
82  {
83  for(boost::property_tree::ptree::value_type &v : doc.get_child("Application.PluginsDirectoriesInfo"))
84  res.push_back(v.second.data());
85  }
86  catch (...)
87  {
88  }
89 
90  return res;
91 }
92 
94  : m_msgBoxParentWidget(nullptr),
95  m_defaultSRID(TE_UNKNOWN_SRS),
96  m_selectionColor(QColor(0, 255, 0)),
97  m_initialized(false),
98  m_resetTerralib(true)
99 {
100 }
101 
103 
104 void te::qt::af::ApplicationController::setConfigFile(const std::string& configFileName)
105 {
106  m_appConfigFile = configFileName;
107 }
108 
110 {
112 }
113 
114 void te::qt::af::ApplicationController::addToolBar(const QString& id, QToolBar* bar)
115 {
116  registerToolBar(id, bar);
117 
118 // send event: tool bar added
120 
121  emit triggered(&evt);
122 }
123 
124 void te::qt::af::ApplicationController::registerToolBar(const QString& id, QToolBar* bar)
125 {
126  QToolBar* b = getToolBar(id);
127 
128  if(b != nullptr)
129  throw Exception(TE_TR("There is already a tool bar registered with the same name!"));
130 
131  m_toolbars[id] = bar;
132 }
133 
134 QToolBar* te::qt::af::ApplicationController::getToolBar(const QString& id) const
135 {
136  std::map<QString, QToolBar*>::const_iterator it = m_toolbars.find(id);
137 
138  return (it != m_toolbars.end()) ? it->second : 0;
139 }
140 
142 {
143  std::vector<QToolBar*> res;
144  std::map<QString, QToolBar*>::const_iterator it;
145 
146  for(it = m_toolbars.begin(); it != m_toolbars.end(); ++it)
147  res.push_back(it->second);
148 
149  return res;
150 }
151 
153 {
154  std::map<QString, QToolBar*>::iterator it = m_toolbars.find(id);
155 
156  if(it != m_toolbars.end())
157  m_toolbars.erase(it);
158 }
159 
161 {
162  m_menus.push_back(mnu);
163 }
164 
165 QMenu* te::qt::af::ApplicationController::findMenu(const QString& id) const
166 {
167  std::vector<QMenu*>::const_iterator it;
168 
169  // Searching in menus vector
170  for(it = m_menus.begin(); it != m_menus.end(); ++it)
171  {
172  QMenu* mnu = te::qt::widgets::FindMenu(id, *it);
173 
174  if(mnu != nullptr)
175  return mnu;
176  }
177 
178  // Searching in menu bars vector
179  std::vector<QMenuBar*>::const_iterator it_bar;
180 
181  for(it_bar = m_menuBars.begin(); it_bar != m_menuBars.end(); ++it_bar)
182  {
183  QMenu* mnu = te::qt::widgets::FindMenu(id, *it_bar);
184 
185  if(mnu != nullptr)
186  return mnu;
187  }
188 
189  return nullptr;
190 }
191 
193 {
194  QMenu* mnu = findMenu(id);
195 
196  if(mnu == nullptr)
197  {
198  if(!m_menuBars.empty())
199  mnu = te::qt::widgets::GetMenu(id, m_menuBars[0]);
200  else
201  {
202  mnu = new QMenu(id);
203  m_menus.push_back(mnu);
204  }
205  }
206 
207  return mnu;
208 }
209 
211 {
212  m_menuBars.push_back(bar);
213 }
214 
216  const QString& /*id*/) const
217 {
218  throw Exception("Not implemented yet.");
219 }
220 
222  const QString& /*id*/) const
223 {
224  return m_menuBars[0];
225 }
226 
227 QAction* te::qt::af::ApplicationController::findAction(const QString& id) const
228 {
229  for(size_t i=0; i<m_menus.size(); i++)
230  {
231  QAction* act = te::qt::widgets::FindAction(id, m_menus[i]);
232 
233  if (act != nullptr)
234  return act;
235  }
236 
237  for(size_t i=0; i<m_menuBars.size(); i++)
238  {
239  QAction* act = te::qt::widgets::FindAction(id, m_menuBars[i]);
240 
241  if (act != nullptr)
242  return act;
243  }
244 
245  return nullptr;
246 }
247 
248 QActionGroup* te::qt::af::ApplicationController::findActionGroup(const QString& id) const
249 {
250  for(size_t i=0; i<m_menus.size(); i++)
251  {
252  QActionGroup* actGroup = te::qt::widgets::FindActionGroup(id, m_menus[i]);
253 
254  if (actGroup != nullptr)
255  return actGroup;
256  }
257 
258  for(size_t i=0; i<m_menuBars.size(); i++)
259  {
260  QActionGroup* actGroup = te::qt::widgets::FindActionGroup(id, m_menuBars[i]);
261 
262  if (actGroup != nullptr)
263  return actGroup;
264  }
265 
266  return nullptr;
267 }
268 
270 {
271  if(type == SENDER || type == BOTH)
272  connect(obj, SIGNAL(triggered(te::qt::af::evt::Event*)),
273  this, SIGNAL(triggered(te::qt::af::evt::Event*)));
274 
275  if(type == RECEIVER || type == BOTH)
276  obj->connect(this, SIGNAL(triggered(te::qt::af::evt::Event*)), SLOT(onApplicationTriggered(te::qt::af::evt::Event*)));
277 }
278 
280 {
281  disconnect(obj);
282 }
283 
285 {
286  if(m_initialized)
287  return;
288 
289  if(m_resetTerralib)
291 
292  SplashScreenManager::getInstance().showMessage(tr("TerraLib Modules loaded!"));
293 
294  SplashScreenManager::getInstance().showMessage(tr("Loading the application configuration file..."));
295 
297 
298 // general application info
299  SplashScreenManager::getInstance().showMessage(tr("Application configuration file loaded!"));
300 
301  m_appName = QString::fromUtf8(te::common::SystemApplicationSettings::getInstance().getValue("Application.Name").c_str());
302  m_appTitle = QString::fromUtf8(te::common::SystemApplicationSettings::getInstance().getValue("Application.Title").c_str());
303  m_appVersion = QApplication::instance()->applicationVersion();
304  m_appIconName = QString::fromUtf8(te::common::SystemApplicationSettings::getInstance().getValue("Application.IconName").c_str());
305 
306  if(!te::core::FileSystem::exists(m_appIconName.toUtf8().data()))
307  m_appIconName = te::core::FindInTerraLibPath(m_appIconName.toUtf8().data()).c_str();
308 
309  m_appPluginsPath = QString::fromUtf8(te::common::SystemApplicationSettings::getInstance().getValue("Application.Plugins.<xmlattr>.xlink:href").c_str());
310 
311  if (!te::core::FileSystem::exists(m_appPluginsPath.toUtf8().data()))
313 
314  m_aboutLogo = QString::fromUtf8(te::common::SystemApplicationSettings::getInstance().getValue("Application.AboutDialogLogo.<xmlattr>.xlink:href").c_str());
315 
316  if(!te::core::FileSystem::exists(m_aboutLogo.toUtf8().data()))
317  m_aboutLogo = te::core::FindInTerraLibPath(m_aboutLogo.toUtf8().data()).c_str();
318 
319  m_tLibLogo = QString::fromUtf8(te::common::SystemApplicationSettings::getInstance().getValue("Application.TerraLibLogo.<xmlattr>.xlink:href").c_str());
320 
321  if(!te::core::FileSystem::exists(m_tLibLogo.toUtf8().data()))
322  m_tLibLogo = te::core::FindInTerraLibPath(m_tLibLogo.toUtf8().data()).c_str();
323 
324  QString fullAppName = m_appName + "-" + m_appVersion;
325  qApp->setApplicationName(fullAppName);
326 
327  m_appOrganization = QString::fromUtf8(te::common::SystemApplicationSettings::getInstance().getValue("Application.Organization").c_str());
328 
329  qApp->setOrganizationName(m_appOrganization);
330 
331  // find user data directory
332 #if QT_VERSION >= 0x050000
333  m_userDataDir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
334 #else
335  m_userDataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
336 #endif
337 
338  if (!te::core::FileSystem::exists(m_userDataDir.toUtf8().data()))
340 
341  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
342 
343  SplashScreenManager::getInstance().showMessage(tr("Loading TerraLib Modules..."));
344 
345  // terralib log startup
346 #ifdef TERRALIB_LOGGER_ENABLED
347  std::string logfile(m_userDataDir.toUtf8().data());
348  logfile += "/log/TerraLib.log";
349  TE_INIT_DEFAULT_LOGGER(logfile);
350 #endif
351 
352 // load help system
353  try
354  {
355  std::string help_file = te::core::FindInTerraLibPath(te::common::SystemApplicationSettings::getInstance().getValue("Application.HelpFile.<xmlattr>.xlink:href"));
356 
357  m_appHelpFile = QString::fromUtf8(help_file.c_str());
358 
359  QFileInfo info(m_appHelpFile);
360 
361  if(!m_appHelpFile.isEmpty() && info.exists())
362  {
363  SplashScreenManager::getInstance().showMessage(tr("Loading application help system..."));
364 
366 
367  te::qt::widgets::HelpManager::getInstance().setImpl(helpImpl);
368 
369  SplashScreenManager::getInstance().showMessage(tr("Application help system loaded!"));
370  }
371  }
372  catch(const std::exception& e)
373  {
374  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
375 
376  QString msgErr(tr("Error loading application help system: %1"));
377 
378  msgErr = msgErr.arg(e.what());
379 
380  QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
381  }
382 
383 // hold user settings
384  QSettings user_settings(QSettings::IniFormat,
385  QSettings::UserScope,
386  QApplication::instance()->organizationName(),
387  QApplication::instance()->applicationName());
388 
389 // load icon theme
390  try
391  {
392  SplashScreenManager::getInstance().showMessage(tr("Loading application icon theme..."));
393 
394  std::string icon_dir = te::core::FindInTerraLibPath(te::common::SystemApplicationSettings::getInstance().getValue("Application.IconThemeInfo.BaseDirectory.<xmlattr>.xlink:href"));
395 
396  m_appIconThemeDir = QString::fromUtf8(icon_dir.c_str());
397 
398  if(!m_appIconThemeDir.isEmpty())
399  {
400  QStringList ithemes = QIcon::themeSearchPaths();
401 
402  ithemes.push_back(m_appIconThemeDir);
403 
404  QIcon::setThemeSearchPaths(ithemes);
405  }
406 
407  m_appDefaultIconTheme = QString::fromUtf8(te::common::SystemApplicationSettings::getInstance().getValue("Application.IconThemeInfo.DefaultTheme").c_str());
408 
409  QVariant iconTheme = user_settings.value("icon_theme/selected_theme", m_appDefaultIconTheme);
410 
411  QIcon::setThemeName(iconTheme.toString());
412 
413  QVariant iconSize = user_settings.value("toolbars/icon_size", te::common::SystemApplicationSettings::getInstance().getValue("Application.ToolBarDefaultIconSize").c_str());
414 
415  {
416  QString sh = QString("QToolBar { qproperty-iconSize: ") + iconSize.toString() + "px " + iconSize.toString() + "px; }";
417  qApp->setStyleSheet(sh);
418  }
419 
420 // Default SRID
421  QVariant srid = user_settings.value("srs/default_srid", te::common::SystemApplicationSettings::getInstance().getValue("Application.DefaultSRID").c_str());
422 
423  m_defaultSRID = srid.toInt();
424 
425 // Selection Color
426  QVariant selectionColor = user_settings.value("color/selection_color", te::common::SystemApplicationSettings::getInstance().getValue("Application.DefaultSelectionColor").c_str());
427 
428  m_selectionColor = QColor(selectionColor.toString());
429 
430  SplashScreenManager::getInstance().showMessage(tr("Application icon theme loaded!"));
431  }
432  catch(const std::exception& e)
433  {
434  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
435 
436  QString msgErr(tr("Error loading application icon theme: %1"));
437 
438  msgErr = msgErr.arg(e.what());
439 
440  QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
441  }
442 
443 // load registered data sources
444  try
445  {
446  m_appDatasourcesFile = user_settings.value("data_sources/data_file", "").toString().toUtf8().data();
447 
448  if(!m_appDatasourcesFile.empty())
449  {
450  SplashScreenManager::getInstance().showMessage(tr("Loading user registered data sources..."));
451 
453 
455 
456  SplashScreenManager::getInstance().showMessage(tr("Known data sources loaded!"));
457  }
458  else
459  {
460  const QString& udir = getUserDataDir();
461 
462  QVariant fileName = udir + "/" + QString(TERRALIB_APPLICATION_DATASOURCE_FILE_NAME);
463 
464  QFileInfo infoDataSourceFile(fileName.toString());
465 
466  int reply = 0;
467  if (infoDataSourceFile.exists())
468  {
470 
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);
472 
474 
475  if (reply == QMessageBox::Yes)
476  {
477  std::string dataSourcesFile = fileName.toString().toUtf8().data();
478 
480 
482 
483  SplashScreenManager::getInstance().showMessage(tr("Known data sources loaded!"));
484  }
485  }
486 
487  // Try to find datasources file of a reformed version
488  if (!infoDataSourceFile.exists() || reply == QMessageBox::No)
489  {
490  std::string lastFormerVersionPath = GetLastFormerVersionPath(this);
491 
492  if (!lastFormerVersionPath.empty())
493  {
494  QVariant fileName = QString::fromUtf8(lastFormerVersionPath.c_str()) + "/" + QString(TERRALIB_APPLICATION_DATASOURCE_FILE_NAME);
495 
496  QFileInfo infoDataSourceFile(fileName.toString());
497 
498  if (infoDataSourceFile.exists())
499  {
501 
502  boost::filesystem::path formerPath(lastFormerVersionPath);
503  std::string appName = formerPath.filename().string();
504 
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?"));
508 
509  reply = QMessageBox::question(nullptr, tr("Data Sources XML"), q, QMessageBox::No, QMessageBox::Yes);
510 
512 
513  if (reply == QMessageBox::Yes)
514  {
515  std::string dataSourcesFile = fileName.toString().toUtf8().data();
516 
518 
520 
521  SplashScreenManager::getInstance().showMessage(tr("Known data sources loaded!"));
522  }
523  }
524  }
525  } // if (!infoDataSourceFile.exists() || reply == QMessageBox::No)
526  }
527  }
528  catch(const std::exception& e)
529  {
530  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
531 
532  QString msgErr(tr("Error loading the registered data sources: %1"));
533 
534  msgErr = msgErr.arg(e.what());
535 
536  QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
537  }
538 
539  m_initialized = true;
540 }
541 
543 {
544  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
545 
546  QSettings user_settings(QSettings::IniFormat, QSettings::UserScope,
547  QApplication::instance()->organizationName(),
548  QApplication::instance()->applicationName());
549 
550  SplashScreenManager::getInstance().showMessage(
551  tr("Loading plugins..."));
552 
553  user_settings.beginGroup("plugins");
554 
555  std::set<std::string> user_loaded_plugins;
556 
557  int nLoaded = user_settings.beginReadArray("loaded");
558 
559  for(int i = 0; i != nLoaded; ++i)
560  {
561  user_settings.setArrayIndex(i);
562 
563  QString name = user_settings.value("name").toString();
564 
565  user_loaded_plugins.insert(name.toUtf8().data());
566  }
567 
568  user_settings.endArray();
569 
570  // get the unloaded plugins
571  std::set<std::string> user_unloaded_plugins;
572  int nUnloaded = user_settings.beginReadArray("unloaded");
573 
574  for(int i = 0; i != nUnloaded; ++i)
575  {
576  user_settings.setArrayIndex(i);
577 
578  QString name = user_settings.value("name").toString();
579 
580  user_unloaded_plugins.insert(name.toUtf8().data());
581  }
582 
583  user_settings.endArray();
584 
585  user_settings.endGroup();
586 
587  if(user_loaded_plugins.size() > 0 || user_unloaded_plugins.size() > 0)
588  {
589  std::vector<te::core::PluginInfo> v_pInfo = te::core::PluginFinder(GetPluginsDirectories(te::common::SystemApplicationSettings::getInstance().getAllSettings()));
590  v_pInfo = te::core::plugin::TopologicalSort(v_pInfo);
591  std::vector<std::string> failToLoad;
592 
593  for(const te::core::PluginInfo& pinfo : v_pInfo)
594  {
595  try
596  {
598  if(user_loaded_plugins.find(pinfo.name) != user_loaded_plugins.end())
600  }
601  catch(...)
602  {
603  failToLoad.push_back(pinfo.name);
604  }
605  }
606  if(failToLoad.size() > 0)
607  {
608  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
609 
610  boost::format err_msg(
611  tr("Could not load the following plugins:\n\n%1%")
612  .toUtf8()
613  .data());
614 
615  QMessageBox msg(
616  QMessageBox::Warning, m_appTitle,
617  (err_msg % boost::algorithm::join(failToLoad, "\n")).str().c_str());
618  msg.setWindowFlags(Qt::WindowStaysOnTopHint);
619  msg.exec();
620  }
621  else
622  {
623  SplashScreenManager::getInstance().showMessage(
624  tr("Plugins loaded successfully!"));
625  }
626  }
627  else
628  {
629  try
630  {
631  SplashScreenManager::getInstance().showMessage(tr("Loading plugins..."));
632 
634 
635  SplashScreenManager::getInstance().showMessage(
636  tr("Plugins loaded successfully!"));
637  }
638  catch(const te::core::Exception& e)
639  {
640  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
641 
642  if(const std::string* d = boost::get_error_info<te::ErrorDescription>(e))
643  {
644  QMessageBox msg(
645  QMessageBox::Warning, m_appTitle, d->c_str());
646  msg.setWindowFlags(Qt::WindowStaysOnTopHint);
647  msg.exec();
648  }
649  else
650  {
651  QMessageBox msg(
652  QMessageBox::Warning, m_appTitle, "An unknown error has occurred");
653  msg.setWindowFlags(Qt::WindowStaysOnTopHint);
654  msg.exec();
655  }
656  }
657  catch(const std::exception& e)
658  {
659  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
660 
661  QString msgErr(tr("Error reading application's plugin list: %1"));
662 
663  msgErr = msgErr.arg(e.what());
664  QMessageBox msg(
665  QMessageBox::Warning, m_appTitle,
666  msgErr);
667  msg.setWindowFlags(Qt::WindowStaysOnTopHint);
668  msg.exec();
669  }
670  }
671 }
672 
674 {
675  if(!m_initialized)
676  return;
677 
679 
680  if(m_resetTerralib)
682 
683  m_appConfigFile.clear();
684 
685  m_applicationItems.clear();
686 
687  m_menuBars.clear();
688 
689  m_menus.clear();
690 
691  m_toolbars.clear();
692 
693  m_aboutLogo.clear();
694 
695  m_appDatasourcesFile.clear();
696 
697  m_appDefaultIconTheme.clear();
698 
699  m_appHelpFile.clear();
700 
701  m_appIconName.clear();
702 
703  m_appIconThemeDir.clear();
704 
705  m_appName.clear();
706 
707  m_msgBoxParentWidget = nullptr;
708 
709  m_appOrganization.clear();
710 
711  m_appTitle.clear();
712 
713  m_tLibLogo.clear();
714 
715  m_appUserSettingsFile.clear();
716 
717  m_appPluginsPath.clear();
718 
720 
721  m_defaultSRID = 0;
722 
723  m_selectionColor = QColor();
724 
725  m_initialized = false;
726 }
727 
729 {
731 }
732 
734 {
735  return m_appSettings;
736 }
737 
739 {
740  return m_appName;
741 }
742 
744 {
745  return m_appTitle;
746 }
747 
749 {
750  return m_appVersion;
751 }
752 
754 {
755  return m_appIconName;
756 }
757 
759 {
760  return m_appPluginsPath;
761 }
762 
764 {
765  return m_aboutLogo;
766 }
767 
769 {
770  return m_tLibLogo;
771 }
772 
774 {
775  return m_defaultSRID;
776 }
777 
779 {
780  return m_selectionColor;
781 }
782 
784 {
785  m_selectionColor = c;
786 }
787 
789 {
790  return m_msgBoxParentWidget;
791 }
792 
794 {
795  m_resetTerralib = status;
796 }
797 
799 {
800  return m_userDataDir;
801 }
802 
804 {
805  emit triggered(e);
806 }
807 
808 void te::qt::af::AppCtrlSingleton::prepareQtEnvironment(const QString& configFileName, const QString& splashFileName)
809 {
810  std::string appName,
811  appTitle,
812  appIconName,
813  aboutLogo,
814  tLibLogo,
815  fullAppName,
816  appOrganization,
817  appIconThemeDir,
818  appDefaultIconTheme;
819 
820  QString userDataDir,
821  appIconThemeName,
822  appIconSize;
823 
825 
826  sysSettings->load(configFileName.toStdString());
827 
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");
833  fullAppName = appName + "-" + te::common::Version::asString();
834  appIconThemeDir = te::core::FindInTerraLibPath(sysSettings->getValue("Application.IconThemeInfo.BaseDirectory.<xmlattr>.xlink:href"));
835  appDefaultIconTheme = sysSettings->getValue("Application.IconThemeInfo.DefaultTheme");
836  appOrganization = sysSettings->getValue("Application.Organization");
837 
838  // Creating config file.
839  qApp->setApplicationName(QString::fromStdString(fullAppName));
840  qApp->setOrganizationName(QString::fromStdString(appOrganization));
841 
842 #if QT_VERSION >= 0x050000
843  userDataDir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
844 #else
845  userDataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
846 #endif
847 
848  QSettings userSettings(QSettings::IniFormat,
849  QSettings::UserScope,
850  qApp->organizationName(),
851  qApp->applicationName());
852 
853  // Check .ini file
854  auto userDataDirS = userDataDir.toStdString();
855 
856  if (!te::core::FileSystem::exists(userDataDirS))
858 
859  // Setting icon theme.
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();
862 
863  QStringList nIthemes;
864 
865  if(!appIconThemeDir.empty())
866  {
867  auto tDir = QString::fromStdString(appIconThemeDir);
868  nIthemes <<tDir;
869  }
870 
871  nIthemes <<QIcon::themeSearchPaths();
872 
873  QIcon::setThemeSearchPaths(nIthemes);
874  QIcon::setThemeName(QString::fromStdString(appIconName));
875 
876  if(!te::core::FileSystem::exists(appIconName))
877  appIconName = te::core::FindInTerraLibPath(appIconName);
878 
879  if(!te::core::FileSystem::exists(aboutLogo))
880  aboutLogo = te::core::FindInTerraLibPath(aboutLogo);
881 
882  if(!te::core::FileSystem::exists(tLibLogo))
883  tLibLogo = te::core::FindInTerraLibPath(tLibLogo);
884 
885  QString iSize = userSettings.value("toolbars/icon_size", QString::fromStdString(sysSettings->getValue("Application.ToolBarDefaultIconSize"))).toString();
886  {
887  QString sh = QString("QToolBar { qproperty-iconSize: ") + iSize + "px " + iSize + "px; }";
888  qApp->setStyleSheet(sh);
889  }
890 
891  // Updating translations path
892  QStringList filters;
893  QFileInfoList lst;
894  QDir dir(QLibraryInfo::location(QLibraryInfo::TranslationsPath));
895 
896  filters <<"*" + QLocale::system().name().toLower() + ".qm";
897 
898  lst = dir.entryInfoList(filters, QDir::Files);
899 
900  for(int i=0; i<lst.size(); ++i)
901  {
902  QTranslator* trans = new QTranslator;
903  trans->load(lst.at(i).baseName(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
904  qApp->installTranslator(trans);
905  }
906 
907  QPixmap pixmap(splashFileName);
908  QSplashScreen* splash = new QSplashScreen(pixmap);
909 
910  splash->setStyleSheet("QWidget { font-size: 12px; font-weight: bold }");
911 
912  te::qt::af::SplashScreenManager::getInstance().set(splash, Qt::AlignBottom | Qt::AlignHCenter, Qt::white);
913 }
914 
916 
917 {
918 
919 }
920 
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)
Definition: Finders.cpp:100
QActionGroup * findActionGroup(const QString &id) const
Returns the action group identified by id or NULL if there&#39;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.
Definition: FileSystem.cpp:142
virtual ~ApplicationController()
Destructor.
TECOREEXPORT std::vector< PluginInfo > TopologicalSort(const std::vector< PluginInfo > &v_pinfo)
TEQTWIDGETSEXPORT QAction * FindAction(const QString &actText, QMenu *mnu)
static bool createDirectories(const std::string &path)
Creates a directory for any element of path that does not exist.
Definition: FileSystem.cpp:153
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.
static void formatDataSourceInfos(const bool &encode)
Formats all data source informations registered in the te::da::DataSourceInfoManager object...
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()
Definition: Version.cpp:60
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.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
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.
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.
int b
Definition: TsRtree.cpp:32
static PluginManager & instance()
Access the singleton.
QMenu * findMenu(const QString &id) const
Returns the menu registered with key id.
TEQTWIDGETSEXPORT QActionGroup * FindActionGroup(const QString &actGroupText, QMenu *mnu)
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.
Definition: Logger.h:197
QString m_appHelpFile
Name of the help file.
QString m_appVersion
The application version.
void removeAllLoggers()
It removes all added loggers.
Definition: Logger.cpp:117
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 *)
TEQTWIDGETSEXPORT QMenu * FindMenu(const QString &mnuText, QMenu *mnu)
Finds a menu item in the mnu object.
QAction * findAction(const QString &id) const
Returns the action identified by id or NULL if there&#39;s not an action identified by id...
QString m_appIconThemeDir
Directory of the application icon theme.
A class for xml serialization formatting strings.
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.
This event signals that a new toolbar was added.
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. ...
TEQTWIDGETSEXPORT QMenu * GetMenu(const QString &mnuText, QMenu *mnu)
Gets a menu or submenu contained in the mnu object.
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.
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.
An object that when created shows a cursor during its scope.
Definition: ScopedCursor.h:48
A help manager that uses the QAssistant to manage help files.
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.