All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include <boost/foreach.hpp> // Boost => don't change this include order, otherwise you may have compiling problems!
28 
29 // TerraLib
30 #include "terralib_config.h"
31 #include "../../common/Exception.h"
32 #include "../../common/PlatformUtils.h"
33 #include "../../common/Translator.h"
34 #include "../../common/TerraLib.h"
35 #include "../../common/SystemApplicationSettings.h"
36 #include "../../common/UserApplicationSettings.h"
37 #include "../../common/Logger.h"
38 #include "../../common/Version.h"
39 #include "../../dataaccess/serialization/xml/Serializer.h"
40 #include "../../plugin/PluginManager.h"
41 #include "../../plugin/PluginInfo.h"
42 #include "../../plugin/Utils.h"
43 #include "../../srs/Config.h"
44 #include "../widgets/help/AssistantHelpManagerImpl.h"
45 #include "../widgets/help/HelpManager.h"
46 #include "../widgets/Utils.h"
47 #include "../widgets/utils/ScopedCursor.h"
49 #include "ApplicationController.h"
50 #include "Exception.h"
51 #include "Project.h"
52 #include "SplashScreenManager.h"
53 #include "Utils.h"
54 #include "XMLFormatter.h"
55 
56 // Qt
57 #include <QApplication>
58 #if QT_VERSION < 0x050000
59 #include <QDesktopServices>
60 #endif
61 #include <QDir>
62 #include <QIcon>
63 #include <QMenu>
64 #include <QMessageBox>
65 #include <QResource>
66 #if QT_VERSION >= 0x050000
67 #include <QStandardPaths>
68 #endif
69 #include <QWidget>
70 
71 // Boost
72 #include <boost/filesystem.hpp>
73 
74 //STL
75 #include <algorithm>
76 
77 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
78 //Log4cxx
79 #include <log4cxx/basicconfigurator.h>
80 #include <log4cxx/consoleappender.h>
81 #include <log4cxx/fileappender.h>
82 #include <log4cxx/helpers/pool.h>
83 #include <log4cxx/helpers/transcoder.h>
84 #include <log4cxx/logger.h>
85 #include <log4cxx/logmanager.h>
86 #include <log4cxx/logstring.h>
87 #include <log4cxx/simplelayout.h>
88 #endif
89 
90 //te::qt::af::ApplicationController* te::qt::af::ApplicationController::sm_instance(0);
91 
93  : QObject(/*parent*/),
94  m_msgBoxParentWidget(0),
95  m_defaultSRID(TE_UNKNOWN_SRS),
96  m_selectionColor(QColor(0, 255, 0)),
97  m_initialized(false),
98  m_project(0),
99  m_resetTerralib(true)
100 {
101 }
102 
104 {
105 
106 }
107 
108 void te::qt::af::ApplicationController::setConfigFile(const std::string& configFileName)
109 {
110  m_appConfigFile = configFileName;
111 }
112 
114 {
115  m_msgBoxParentWidget = w;
116 }
117 
118 void te::qt::af::ApplicationController::addToolBar(const QString& id, QToolBar* bar)
119 {
120  registerToolBar(id, bar);
121 
122 // send event: tool bar added
124 
125  broadcast(&evt);
126 }
127 
128 void te::qt::af::ApplicationController::registerToolBar(const QString& id, QToolBar* bar)
129 {
130  QToolBar* b = getToolBar(id);
131 
132  if(b != 0)
133  throw Exception(TE_TR("There is already a tool bar registered with the same name!"));
134 
135  m_toolbars[id] = bar;
136 }
137 
138 QToolBar* te::qt::af::ApplicationController::getToolBar(const QString& id) const
139 {
140  std::map<QString, QToolBar*>::const_iterator it = m_toolbars.find(id);
141 
142  return (it != m_toolbars.end()) ? it->second : 0;
143 }
144 
146 {
147  std::vector<QToolBar*> res;
148  std::map<QString, QToolBar*>::const_iterator it;
149 
150  for(it = m_toolbars.begin(); it != m_toolbars.end(); ++it)
151  res.push_back(it->second);
152 
153  return res;
154 }
155 
157 {
158  std::map<QString, QToolBar*>::iterator it = m_toolbars.find(id);
159 
160  if(it != m_toolbars.end())
161  m_toolbars.erase(it);
162 }
163 
165 {
166  m_menus.push_back(mnu);
167 }
168 
169 QMenu* te::qt::af::ApplicationController::findMenu(const QString& id) const
170 {
171  std::vector<QMenu*>::const_iterator it;
172 
173  // Searching in menus vector
174  for(it = m_menus.begin(); it != m_menus.end(); ++it)
175  {
176  QMenu* mnu = te::qt::widgets::FindMenu(id, *it);
177 
178  if(mnu != 0)
179  return mnu;
180  }
181 
182  // Searching in menu bars vector
183  std::vector<QMenuBar*>::const_iterator it_bar;
184 
185  for(it_bar = m_menuBars.begin(); it_bar != m_menuBars.end(); ++it_bar)
186  {
187  QMenu* mnu = te::qt::widgets::FindMenu(id, *it_bar);
188 
189  if(mnu != 0)
190  return mnu;
191  }
192 
193  return 0;
194 }
195 
197 {
198  QMenu* mnu = findMenu(id);
199 
200  if(mnu == 0)
201  {
202  if(!m_menuBars.empty())
203  mnu = te::qt::widgets::GetMenu(id, m_menuBars[0]);
204  else
205  {
206  mnu = new QMenu(id);
207  m_menus.push_back(mnu);
208  }
209  }
210 
211  return mnu;
212 }
213 
215 {
216  m_menuBars.push_back(bar);
217 }
218 
219 QMenuBar* te::qt::af::ApplicationController::findMenuBar(const QString& id) const
220 {
221  throw Exception("Not implemented yet.");
222 }
223 
224 QMenuBar* te::qt::af::ApplicationController::getMenuBar(const QString& id) const
225 {
226  return m_menuBars[0];
227 }
228 
229 QAction* te::qt::af::ApplicationController::findAction(const QString& id) const
230 {
231  for(size_t i=0; i<m_menus.size(); i++)
232  {
233  QAction* act = te::qt::widgets::FindAction(id, m_menus[i]);
234 
235  if (act != 0)
236  return act;
237  }
238 
239  for(size_t i=0; i<m_menuBars.size(); i++)
240  {
241  QAction* act = te::qt::widgets::FindAction(id, m_menuBars[i]);
242 
243  if (act != 0)
244  return act;
245  }
246 
247  return 0;
248 }
249 
250 QActionGroup* te::qt::af::ApplicationController::findActionGroup(const QString& id) const
251 {
252  for(size_t i=0; i<m_menus.size(); i++)
253  {
254  QActionGroup* actGroup = te::qt::widgets::FindActionGroup(id, m_menus[i]);
255 
256  if (actGroup != 0)
257  return actGroup;
258  }
259 
260  for(size_t i=0; i<m_menuBars.size(); i++)
261  {
262  QActionGroup* actGroup = te::qt::widgets::FindActionGroup(id, m_menuBars[i]);
263 
264  if (actGroup != 0)
265  return actGroup;
266  }
267 
268  return 0;
269 }
270 
272 {
273  std::set<QObject*>::const_iterator it = m_applicationItems.find(obj);
274 
275  if(it != m_applicationItems.end())
276  return;
277 
278  m_applicationItems.insert(obj);
279 
280  obj->connect(this, SIGNAL(triggered(te::qt::af::evt::Event*)), SLOT(onApplicationTriggered(te::qt::af::evt::Event*)));
281 }
282 
284 {
285  std::set<QObject*>::iterator it = m_applicationItems.find(obj);
286 
287  if(it == m_applicationItems.end())
288  return;
289 
290  m_applicationItems.erase(it);
291 
292  disconnect(SIGNAL(triggered(te::qt::af::evt::Event*)), obj, SLOT(onApplicationTriggered(te::qt::af::evt::Event*)));
293 }
294 
296 {
297  if(m_initialized)
298  return;
299 
300 // find user data directory
301 #if QT_VERSION >= 0x050000
302  m_userDataDir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
303 #else
304  m_userDataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
305 #endif
306 
307  if(!boost::filesystem::exists(m_userDataDir.toStdString()))
308  boost::filesystem::create_directories(m_userDataDir.toStdString());
309 
310  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
311 
312  SplashScreenManager::getInstance().showMessage(tr("Loading TerraLib Modules..."));
313 
314 // terralib log startup
315 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
316  std::string path = m_userDataDir.toStdString();
317  path += "/log/terralib.log";
318 
319  log4cxx::FileAppender* fileAppender = new log4cxx::FileAppender(log4cxx::LayoutPtr(new log4cxx::SimpleLayout()),
320  log4cxx::helpers::Transcoder::decode(path.c_str()), false);
321 
322  log4cxx::helpers::Pool p;
323  fileAppender->activateOptions(p);
324 
325  log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(fileAppender));
326  log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getAll() /*log4cxx::Level::getDebug()*/);
327  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("te");
328 #endif
329  //LOG4CXX_INFO(logger, "Created FileAppender appender");
330 
331  if(m_resetTerralib)
333 
334  SplashScreenManager::getInstance().showMessage(tr("TerraLib Modules loaded!"));
335 
336  SplashScreenManager::getInstance().showMessage(tr("Loading the application configuration file..."));
337 
339 
340 // general application info
341  SplashScreenManager::getInstance().showMessage(tr("Application configuration file loaded!"));
342 
343  m_appName = QString::fromStdString(te::common::SystemApplicationSettings::getInstance().getValue("Application.Name"));
344  m_appTitle = QString::fromStdString(te::common::SystemApplicationSettings::getInstance().getValue("Application.Title"));
345  m_appProjectExtension = QString::fromStdString(te::common::SystemApplicationSettings::getInstance().getValue("Application.ProjectExtension"));
346  m_appIconName = QString::fromStdString(te::common::SystemApplicationSettings::getInstance().getValue("Application.IconName"));
347 
348  if(!boost::filesystem::exists(m_appIconName.toStdString()))
349  m_appIconName = te::common::FindInTerraLibPath(m_appIconName.toStdString()).c_str();
350 
351  m_appPluginsPath = QString::fromStdString(te::common::SystemApplicationSettings::getInstance().getValue("Application.Plugins.<xmlattr>.xlink:href"));
352 
353  if (!boost::filesystem::exists(m_appPluginsPath.toStdString()))
354  m_appPluginsPath = te::common::FindInTerraLibPath(m_appPluginsPath.toStdString()).c_str();
355 
356  m_aboutLogo = QString::fromStdString(te::common::SystemApplicationSettings::getInstance().getValue("Application.AboutDialogLogo.<xmlattr>.xlink:href"));
357 
358  if(!boost::filesystem::exists(m_aboutLogo.toStdString()))
359  m_aboutLogo = te::common::FindInTerraLibPath(m_aboutLogo.toStdString()).c_str();
360 
361  m_tLibLogo = QString::fromStdString(te::common::SystemApplicationSettings::getInstance().getValue("Application.TerraLibLogo.<xmlattr>.xlink:href"));
362 
363  if(!boost::filesystem::exists(m_tLibLogo.toStdString()))
364  m_tLibLogo = te::common::FindInTerraLibPath(m_tLibLogo.toStdString()).c_str();
365 
366  QString fullAppName = m_appName + "-" + QString(te::common::Version::asString().c_str());
367  qApp->setApplicationName(fullAppName);
368 
369  m_appOrganization = QString::fromStdString(te::common::SystemApplicationSettings::getInstance().getValue("Application.Organization"));
370 
371  qApp->setOrganizationName(m_appOrganization);
372 
373 // load help system
374  try
375  {
376  std::string help_file = te::common::FindInTerraLibPath(te::common::SystemApplicationSettings::getInstance().getValue("Application.HelpFile.<xmlattr>.xlink:href"));
377 
378  m_appHelpFile = QString::fromStdString(help_file);
379 
380  QFileInfo info(m_appHelpFile);
381 
382  if(!m_appHelpFile.isEmpty() && info.exists())
383  {
384  SplashScreenManager::getInstance().showMessage(tr("Loading application help system..."));
385 
387 
388  te::qt::widgets::HelpManager::getInstance().setImpl(helpImpl);
389 
390  SplashScreenManager::getInstance().showMessage(tr("Application help system loaded!"));
391  }
392  }
393  catch(const std::exception& e)
394  {
395  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
396 
397  QString msgErr(tr("Error loading application help system: %1"));
398 
399  msgErr = msgErr.arg(e.what());
400 
401  QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
402  }
403 
404 // hold user settings
405  QSettings user_settings(QSettings::IniFormat,
406  QSettings::UserScope,
407  QApplication::instance()->organizationName(),
408  QApplication::instance()->applicationName());
409 
410 // load icon theme
411  try
412  {
413  SplashScreenManager::getInstance().showMessage(tr("Loading application icon theme..."));
414 
415  std::string icon_dir = te::common::FindInTerraLibPath(te::common::SystemApplicationSettings::getInstance().getValue("Application.IconThemeInfo.BaseDirectory.<xmlattr>.xlink:href"));
416 
417  m_appIconThemeDir = QString::fromStdString(icon_dir);
418 
419  if(!m_appIconThemeDir.isEmpty())
420  {
421  QStringList ithemes = QIcon::themeSearchPaths();
422 
423  ithemes.push_back(m_appIconThemeDir);
424 
425  QIcon::setThemeSearchPaths(ithemes);
426  }
427 
428  m_appDefaultIconTheme = QString::fromStdString(te::common::SystemApplicationSettings::getInstance().getValue("Application.IconThemeInfo.DefaultTheme"));
429 
430  QVariant iconTheme = user_settings.value("icon_theme/selected_theme", m_appDefaultIconTheme);
431 
432  QIcon::setThemeName(iconTheme.toString());
433 
434  QVariant iconSize = user_settings.value("toolbars/icon_size", te::common::SystemApplicationSettings::getInstance().getValue("Application.ToolBarDefaultIconSize").c_str());
435 
436  {
437  QString sh = QString("QToolBar { qproperty-iconSize: ") + iconSize.toString() + "px " + iconSize.toString() + "px; }";
438  qApp->setStyleSheet(sh);
439  }
440 
441 // Default SRID
442  QVariant srid = user_settings.value("srs/default_srid", te::common::SystemApplicationSettings::getInstance().getValue("Application.DefaultSRID").c_str());
443 
444  m_defaultSRID = srid.toInt();
445 
446 // Selection Color
447  QVariant selectionColor = user_settings.value("color/selection_color", te::common::SystemApplicationSettings::getInstance().getValue("Application.DefaultSelectionColor").c_str());
448 
449  m_selectionColor = QColor(selectionColor.toString());
450 
451  SplashScreenManager::getInstance().showMessage(tr("Application icon theme loaded!"));
452  }
453  catch(const std::exception& e)
454  {
455  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
456 
457  QString msgErr(tr("Error loading application icon theme: %1"));
458 
459  msgErr = msgErr.arg(e.what());
460 
461  QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
462  }
463 
464 // load registered data sources
465  try
466  {
467  m_appDatasourcesFile = user_settings.value("data_sources/data_file", "").toString().toStdString();
468 
469  if(!m_appDatasourcesFile.empty())
470  {
471  SplashScreenManager::getInstance().showMessage(tr("Loading user registered data sources..."));
472 
473  te::serialize::xml::ReadDataSourceInfo(m_appDatasourcesFile);
474 
476 
477  SplashScreenManager::getInstance().showMessage(tr("Known data sources loaded!"));
478  }
479  else
480  {
481  const QString& udir = getUserDataDir();
482 
483  QVariant fileName = udir + "/" + QString(TERRALIB_APPLICATION_DATASOURCE_FILE_NAME);
484 
485  QFileInfo infoDataSourceFile(fileName.toString());
486 
487  if (infoDataSourceFile.exists())
488  {
489  int reply = QMessageBox::question(0, tr("Data Sources XML"), tr("A file containing data sources already configured was found. Would you like to load it."), QMessageBox::No, QMessageBox::Yes);
490 
491  if (reply == QMessageBox::Yes)
492  {
493  std::string dataSourcesFile = fileName.toString().toStdString();
494 
496 
498 
499  SplashScreenManager::getInstance().showMessage(tr("Known data sources loaded!"));
500  }
501  }
502  }
503  }
504  catch(const std::exception& e)
505  {
506  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
507 
508  QString msgErr(tr("Error loading the registered data sources: %1"));
509 
510  msgErr = msgErr.arg(e.what());
511 
512  QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
513  }
514 
515  QFileInfo info(user_settings.fileName());
516 
517  if(!info.exists())
519 
520  m_initialized = true;
521 }
522 
524 {
525  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
526 
527  std::vector<std::string> plgFiles;
528 
529  try
530  {
531  SplashScreenManager::getInstance().showMessage(tr("Reading application plugins list..."));
532 
533  std::vector<std::string> default_plg = GetDefaultPluginsNames();
534  plgFiles = GetPluginsFiles();
535 
536  //SplashScreenManager::getInstance().showMessage(tr("Plugins list read!"));
537 
538  SplashScreenManager::getInstance().showMessage(tr("Checking enabled plugins..."));
539 
540  QSettings user_settings(QSettings::IniFormat,
541  QSettings::UserScope,
542  QApplication::instance()->organizationName(),
543  QApplication::instance()->applicationName());
544 
545  user_settings.beginGroup("plugins");
546 
547  std::set<std::string> user_enabled_plugins;
548 
549  int nitems = user_settings.beginReadArray("enabled");
550 
551  for(int i = 0; i != nitems; ++i)
552  {
553  user_settings.setArrayIndex(i);
554 
555  QString name = user_settings.value("name").toString();
556 
557  user_enabled_plugins.insert(name.toStdString());
558  }
559 
560  user_settings.endArray();
561 
562  // get the unloaded plugins
563  std::set<std::string> user_unloaded_plugins;
564  int n_itemsUnloaded = user_settings.beginReadArray("unloaded");
565 
566  for (int i = 0; i != n_itemsUnloaded; ++i)
567  {
568  user_settings.setArrayIndex(i);
569 
570  QString name = user_settings.value("name").toString();
571 
572  user_unloaded_plugins.insert(name.toStdString());
573  }
574 
575  user_settings.endArray();
576 
577  // get the broken plugins
578  std::set<std::string> user_broken_plugins;
579  int n_itemsBroken = user_settings.beginReadArray("broken");
580 
581  for (int i = 0; i != n_itemsBroken; ++i)
582  {
583  user_settings.setArrayIndex(i);
584 
585  QString name = user_settings.value("name").toString();
586 
587  user_broken_plugins.insert(name.toStdString());
588  }
589 
590  user_settings.endArray();
591 
592  user_settings.endGroup();
593 
594  //SplashScreenManager::getInstance().showMessage(tr("Enabled plugin list read!"));
595 
596  SplashScreenManager::getInstance().showMessage(tr("Loading plugins..."));
597 
598 // retrieve information for each plugin
599  boost::ptr_vector<te::plugin::PluginInfo> plugins;
600  boost::ptr_vector<te::plugin::PluginInfo> unloadedPlugins;
601  boost::ptr_vector<te::plugin::PluginInfo> brokenPlugins;
602 
603  for(std::size_t i = 0; i != plgFiles.size(); ++i)
604  {
606 
607  if (user_enabled_plugins.empty()) // if there is no list of enabled plugins
608  {
609  if (default_plg.size() > 0)
610  {
611  if (std::find(default_plg.begin(), default_plg.end(), pinfo->m_name) != default_plg.end())
612  plugins.push_back(pinfo); // try to load all default plugins.
613  }
614  else
615  {
616  plugins.push_back(pinfo); // try to load all plugins.
617  }
618  }
619  else if (user_enabled_plugins.count(pinfo->m_name) != 0) // else, if a list is available,
620  {
621  plugins.push_back(pinfo); // load all enabled plugins using .ini file as reference.
622  }
623  else if (user_unloaded_plugins.count(pinfo->m_name) != 0) // else, if a list is available,
624  {
625  unloadedPlugins.push_back(pinfo); // load only unloaded plugins
626  }
627  else if (user_broken_plugins.count(pinfo->m_name) != 0) // else, if a list is available,
628  {
629  brokenPlugins.push_back(pinfo); // load only broken plugins
630  }
631  }
632 
633 // load and start each plugin
635 
636  if (user_unloaded_plugins.size() > 0)
637  te::plugin::PluginManager::getInstance().setUnloadedPlugins(unloadedPlugins);
638 
639  if (user_broken_plugins.size() > 0)
640  te::plugin::PluginManager::getInstance().setBrokenPlugins(brokenPlugins);
641 
642  SplashScreenManager::getInstance().showMessage(tr("Plugins loaded successfully!"));
643  }
644  catch(const std::exception& e)
645  {
646  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
647 
648  QString msgErr(tr("Error reading application's plugin list: %1"));
649 
650  msgErr = msgErr.arg(e.what());
651 
652  QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
653  }
654 }
655 
657 {
658  SplashScreenManager::getInstance().showMessage("Loading recent projects...");
659 
660  try
661  {
662  QSettings user_settings(QSettings::IniFormat,
663  QSettings::UserScope,
664  QApplication::instance()->organizationName(),
665  QApplication::instance()->applicationName());
666 
667  QVariant projPath = user_settings.value("projects/most_recent/path", "");
668  QVariant projTitle = user_settings.value("projects/most_recent/title", "");
669 
670  QMenu* mnu = getMenu("File.Recent Projects");
671 
672  if(!projPath.toString().isEmpty())
673  {
674  QAction* act = mnu->addAction(projPath.toString());
675  act->setData(projPath);
676 
677  mnu->addSeparator();
678 
679  m_recentProjs.append(projPath.toString());
680  m_recentProjsTitles.append(projTitle.toString());
681  }
682 
683  user_settings.beginGroup("projects");
684 
685  int nrc = user_settings.beginReadArray("recents");
686 
687  for(int i = 0; i != nrc; ++i)
688  {
689  user_settings.setArrayIndex(i);
690  QString npath = user_settings.value("projects/path").toString();
691  QString ntitle = user_settings.value("projects/title").toString();
692 
693 
694  QAction* act = mnu->addAction(npath);
695  act->setData(npath);
696  m_recentProjs.append(npath);
697  m_recentProjsTitles.append(ntitle);
698  }
699 
700  mnu->setEnabled(true);
701 
702  SplashScreenManager::getInstance().showMessage("Recent projects loaded!");
703  }
704  catch(const std::exception& e)
705  {
706  te::qt::widgets::ScopedCursor acursor(Qt::ArrowCursor);
707 
708  QString msgErr(tr("Error loading the registered projects: %1"));
709 
710  msgErr = msgErr.arg(e.what());
711 
712  QMessageBox::warning(m_msgBoxParentWidget, m_appTitle, msgErr);
713  }
714 }
715 
716 void te::qt::af::ApplicationController::updateRecentProjects(const QString& prjFile, const QString& prjTitle)
717 {
718  int pos = m_recentProjs.indexOf(prjFile);
719 
720  QString author;
721  int maxSaved;
722 
723  GetProjectInformationsFromSettings(author, maxSaved);
724 
725  if(pos != 0)
726  {
727  if(pos < 0)
728  {
729  if(m_recentProjs.size() > maxSaved) // TODO: Size of the list must be configurable.
730  {
731  m_recentProjs.removeLast();
732  m_recentProjsTitles.removeLast();
733  }
734 
735  m_recentProjs.prepend(prjFile);
736  m_recentProjsTitles.prepend(prjTitle);
737  }
738  else
739  {
740  m_recentProjs.move(pos, 0);
741  m_recentProjsTitles.move(pos, 0);
742  }
743 
744  if(m_recentProjs.isEmpty())
745  return;
746 
747  QMenu* mnu = getMenu("File.Recent Projects");
748 
749  mnu->clear();
750 
751  mnu->setEnabled(true);
752 
753  QString recPrj = m_recentProjs.at(0);
754  QAction* act = mnu->addAction(recPrj);
755  act->setData(recPrj);
756 
757  mnu->addSeparator();
758 
759  if(m_recentProjs.size() > 1)
760  for(int i=1; i<m_recentProjs.size(); i++)
761  {
762  recPrj = m_recentProjs.at(i);
763  act = mnu->addAction(recPrj);
764  act->setData(recPrj);
765  }
766  }
767 
768  QAction* act = findAction("File.Save Project As");
769 
770  if(act != 0)
771  act->setEnabled(true);
772 }
773 
775 {
776  m_project = prj;
777 }
778 
780 {
781  return m_project;
782 }
783 
785 {
786  if(!m_initialized)
787  return;
788 
789  UpdateUserSettings(m_recentProjs, m_recentProjsTitles, m_appUserSettingsFile);
790 
792 
794 
796 
798 
799  if(m_resetTerralib)
801 
802  m_appConfigFile.clear();
803 
804  m_applicationItems.clear();
805 
806  m_menuBars.clear();
807 
808  m_menus.clear();
809 
810  m_toolbars.clear();
811 
812  m_aboutLogo.clear();
813 
814  m_appDatasourcesFile.clear();
815 
816  m_appDefaultIconTheme.clear();
817 
818  m_appHelpFile.clear();
819 
820  m_appIconName.clear();
821 
822  m_appIconThemeDir.clear();
823 
824  m_appName.clear();
825 
826  m_msgBoxParentWidget = 0;
827 
828  m_appOrganization.clear();
829 
830  m_appTitle.clear();
831 
832  m_appProjectExtension.clear();
833 
834  m_tLibLogo.clear();
835 
836  m_recentProjs.clear();
837 
838  m_recentProjsTitles.clear();
839 
840  m_appUserSettingsFile.clear();
841 
842  m_appPluginsPath.clear();
843 
844  m_appToolBarDefaultIconSize.clear();
845 
846  m_defaultSRID = 0;
847 
848  m_selectionColor = QColor();
849 
850  m_project = 0;
851 
852  m_initialized = false;
853 }
854 
856 {
857  return m_appSettings;
858 }
859 
861 {
862  // Need to check event send to prevent loops
863  // -----------------------------------------
864 
865  emit triggered(evt);
866 }
867 
869 {
870  return m_appName;
871 }
872 
874 {
875  return m_appTitle;
876 }
877 
879 {
880  return m_appProjectExtension;
881 }
882 
884 {
885  return m_appIconName;
886 }
887 
889 {
890  return m_appPluginsPath;
891 }
892 
894 {
895  return m_aboutLogo;
896 }
897 
899 {
900  return m_tLibLogo;
901 }
902 
904 {
905  return m_recentProjs.isEmpty() ? QString("") : m_recentProjs.front();
906 }
907 
909 {
910  return m_defaultSRID;
911 }
912 
914 {
915  return m_selectionColor;
916 }
917 
919 {
920  m_selectionColor = c;
921 }
922 
924 {
925  return m_msgBoxParentWidget;
926 }
927 
929 {
930  m_resetTerralib = status;
931 }
932 
934 {
935  return m_userDataDir;
936 }
TEQTAFEXPORT std::vector< std::string > GetPluginsFiles()
Definition: Utils.cpp:794
virtual void setConfigFile(const std::string &configFileName)
It gives access to the controller singleton.
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.
std::string m_name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
Definition: PluginInfo.h:66
TEQTWIDGETSEXPORT QAction * FindAction(const QString &actText, QMenu *mnu)
Definition: Utils.cpp:137
TEQTAFEXPORT void CreateDefaultSettings()
Creates a default QSettings.
Definition: Utils.cpp:621
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.
Definition: Event.h:59
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()
Definition: Version.cpp:60
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.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
TEQTAFEXPORT void UpdateUserSettings(const QStringList &prjFiles, const QStringList &prjTitles, const std::string &userConfigFile)
Updates user settings file section about information of the projects.
Definition: Utils.cpp:320
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.
Definition: Utils.cpp:413
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.
QMenu * findMenu(const QString &id) const
Returns the menu registered with key id.
TEQTWIDGETSEXPORT QActionGroup * FindActionGroup(const QString &actGroupText, QMenu *mnu)
Definition: Utils.cpp:147
QColor getSelectionColor() const
Returns the application selection color.
const QString & getAppPluginsPath() const
Returns the plugins file path of application.
void finalize()
It finalizes the TerraLib Platform.
Definition: TerraLib.cpp:64
static SplashScreenManager & getInstance()
It returns a reference to the singleton instance.
TEQTAFEXPORT std::vector< std::string > GetDefaultPluginsNames()
Definition: Utils.cpp:814
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.
Definition: Config.h:44
void addListener(QObject *obj)
Insert an application item that will listen to framework events.
TEQTAFEXPORT void GetProjectInformationsFromSettings(QString &defaultAuthor, int &maxSaved)
Definition: Utils.cpp:567
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.
const QString & getAppProjectExtension() const
Returns the application project extension.
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.
Definition: TerraLib.cpp:33
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.
Definition: urisyn.cpp:171
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.
TEQTWIDGETSEXPORT QMenu * FindMenu(const QString &mnuText, QMenu *mnu)
Finds a menu item in the mnu object.
Definition: Utils.cpp:127
This class models the concept of a project for the TerraLib Application Framework.
Definition: Project.h:50
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.
This event signals that a new toolbar was added.
TEQTWIDGETSEXPORT QMenu * GetMenu(const QString &mnuText, QMenu *mnu)
Gets a menu or submenu contained in the mnu object.
Definition: Utils.cpp:192
The basic information about a plugin.
Definition: PluginInfo.h:61
A class for xml serialization formatting strings.
QString getMostRecentProject() const
Returns the most recent project.
#define TERRALIB_APPLICATION_DATASOURCE_FILE_NAME
The default name for the application file containing the list of data sources.
Definition: Config.h:44
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...
Definition: Utils.cpp:80
static void formatDataSourceInfos(const bool &encode)
Formats all data source informations registered in the te::da::DataSourceInfoManager object...
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)
Definition: Serializer.cpp:90
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.