All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Plugin.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/plugins/addressgeocoding/Plugin.cpp
22 
23  \brief Plugin implementation for the Address Geocoding Qt Plugin widget.
24 */
25 
26 // TerraLib
27 #include "terralib_config.h"
28 #include "../../../addressgeocoding/qt/MainWindowDialog.h"
29 #include "../../../common/Config.h"
30 #include "../../../common/Translator.h"
31 #include "../../../common/Logger.h"
32 #include "../../af/ApplicationController.h"
33 #include "../../af/events/LayerEvents.h"
34 #include "../../af/Project.h"
35 #include "../../af/Utils.h"
36 #include "Plugin.h"
37 
38 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
39 //Log4cxx
40 #include <log4cxx/basicconfigurator.h>
41 #include <log4cxx/consoleappender.h>
42 #include <log4cxx/fileappender.h>
43 #include <log4cxx/helpers/pool.h>
44 #include <log4cxx/helpers/transcoder.h>
45 #include <log4cxx/logger.h>
46 #include <log4cxx/logmanager.h>
47 #include <log4cxx/logstring.h>
48 #include <log4cxx/patternlayout.h>
49 #include <log4cxx/rollingfileappender.h>
50 #include <log4cxx/simplelayout.h>
51 #endif
52 
53 // QT
54 #include <QAction>
55 #include <QtCore/QObject>
56 #include <QMenu>
57 #include <QMenuBar>
58 #include <QMessageBox>
59 
61  : te::plugin::Plugin(pluginInfo)
62 {
63 }
64 
66 {
67 }
68 
70 {
71  if(m_initialized)
72  return;
73 
74  TE_LOG_TRACE(TE_TR("TerraLib Qt Address Geocoding Plugin startup!"));
75 
76 // add plugin menu
77  QMenu* pluginMenu = te::qt::af::ApplicationController::getInstance().getMenu("Processing");
78 
79  m_action = new QAction(pluginMenu);
80  m_action->setText("Address Geocoding...");
81  m_action->setIcon(QIcon::fromTheme("addressgeocoding-icon"));
82  m_action->setObjectName("Processing.Address Geocoding");
83 
84  connect(m_action, SIGNAL(triggered(bool)), this, SLOT(onActionActivated(bool)));
85 
86 // Insert action before plugin manager action
87  QAction* pluginsSeparator = te::qt::af::ApplicationController::getInstance().findAction("ManagePluginsSeparator");
88  pluginMenu->insertAction(pluginsSeparator, m_action);
89 
90 // address geocoding log startup
91  std::string path = te::qt::af::ApplicationController::getInstance().getUserDataDir().toStdString();
92  path += "/log/terralib_addressgeocoding.log";
93 
94 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
95  std::string layout = "%d{ISO8601} [%t] %-5p %c - %m%n";
96  log4cxx::LogString lString(layout.begin(), layout.end());
97 
98  log4cxx::FileAppender* fileAppender = new log4cxx::RollingFileAppender(log4cxx::LayoutPtr(new log4cxx::PatternLayout(lString)),
99  log4cxx::helpers::Transcoder::decode(path.c_str()), true);
100 
101  log4cxx::helpers::Pool p;
102  fileAppender->activateOptions(p);
103 
104  log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(fileAppender));
105  log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
106 
107  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("addressgeocoding");
108  logger->setAdditivity(false);
109  logger->addAppender(fileAppender);
110 #endif
111 
113 
114  m_initialized = true;
115 }
116 
118 {
119  if(!m_initialized)
120  return;
121 
122 // unregister actions
123  unRegisterActions();
124 
125 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
126  log4cxx::LogManager::shutdown();
127 #endif
128 
129  TE_LOG_TRACE(TE_TR("TerraLib Qt Address Geocoding Plugin shutdown!"));
130 
131  m_initialized = false;
132 }
133 
135 {
136  QWidget* parent = te::qt::af::ApplicationController::getInstance().getMainWindow();
138 
139  // get the list of layers from current project
141 
142  if(prj)
143  {
144  dlg.setLayers(prj->getSingleLayers(false));
145  }
146 
147  if(dlg.exec() != QDialog::Accepted)
148  return;
149 
150  te::map::AbstractLayerPtr layer = dlg.getLayer();
151 
152  if(!layer)
153  return;
154 
155  int reply = QMessageBox::question(0, tr("Address Geocoding Result"), tr("The operation was concluded successfully. Would you like to add the layer to the project?"), QMessageBox::No, QMessageBox::Yes);
156 
157  if(prj && reply == QMessageBox::Yes)
158  {
159  te::qt::af::evt::LayerAdded evt(layer);
160 
162  }
163 }
164 
165 std::list<te::map::AbstractLayerPtr> te::qt::plugins::addressgeocoding::Plugin::getLayers()
166 {
167  std::list<te::map::AbstractLayerPtr> list;
168 
170 
171  if(prj)
172  list = prj->getAllLayers(false);
173 
174  return list;
175 }
176 
177 
179 {
180  delete m_action;
181 }
182 
#define TE_LOG_TRACE(msg)
Use this tag in order to log a message to a specified logger with the TRACE level.
Definition: Logger.h:137
This event signals that a new layer was created.
Definition: LayerEvents.h:66
std::list< te::map::AbstractLayerPtr > getLayers()
Get the list of layers from app.
Definition: Plugin.cpp:165
void startup()
Do nothing! Just set plugin as started.
Definition: Plugin.cpp:69
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
std::list< te::map::AbstractLayerPtr > getAllLayers(bool invalid=true)
It gets all the layers (single and folder layers) of the project.
Definition: Project.cpp:77
#define PLUGIN_CALL_BACK_IMPL(PLUGIN_CLASS_NAME)
This macro should be used by C++ plugins in order to declare the exportable/callable DLL function...
Definition: Config.h:57
TEQTAFEXPORT void AddActionToCustomToolbars(QAction *act)
Check QSettings for existance of act and adds it if necessary.
Definition: Utils.cpp:763
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
std::list< te::map::AbstractLayerPtr > getSingleLayers(bool invalid=true)
It gets all the single layers of the project.
Definition: Project.cpp:113
Plugin implementation for the SA Qt Plugin widget.
Plugin(const te::plugin::PluginInfo &pluginInfo)
Definition: Plugin.cpp:60
bool decode(std::string &s)
Decode the pct-encoded (hex) sequences, if any, return success.
Definition: urisyn.cpp:171
void unRegisterActions()
Function used to unregister all addressgeocoding actions.
Definition: Plugin.cpp:178
This class models the concept of a project for the TerraLib Application Framework.
Definition: Project.h:50
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
te::map::AbstractLayerPtr getLayer()
Get the generated layer.
void onActionActivated(bool checked)
Slot function used when a action was selected.
Definition: Plugin.cpp:134
The basic information about a plugin.
Definition: PluginInfo.h:61
void shutdown()
Do nothing! Just set plugin as stopped.
Definition: Plugin.cpp:117
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr