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/layout/Plugin.cpp
22 
23  \brief Plugin implementation for the LayoutEditor Qt Plugin widget.
24 */
25 
26 // TerraLib
27 #include "terralib_config.h"
28 #include "../../../common/Config.h"
29 #include "../../../common/Translator.h"
30 #include "../../../common/Logger.h"
31 #include "../../af/ApplicationController.h"
32 #include "Plugin.h"
33 
34 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
35 //Log4cxx
36 #include <log4cxx/basicconfigurator.h>
37 #include <log4cxx/consoleappender.h>
38 #include <log4cxx/fileappender.h>
39 #include <log4cxx/helpers/pool.h>
40 #include <log4cxx/helpers/transcoder.h>
41 #include <log4cxx/logger.h>
42 #include <log4cxx/logmanager.h>
43 #include <log4cxx/logstring.h>
44 #include <log4cxx/simplelayout.h>
45 #include <log4cxx/patternlayout.h>
46 #include <log4cxx/rollingfileappender.h>
47 #endif
48 
49 #ifdef TE_QT_PLUGIN_LAYOUT_HAVE_LAYOUTEDITOR
50  #include "LayoutEditorAction.h"
51 #endif
52 
53 // QT
54 #include <QMenu>
55 #include <QMenuBar>
56 
58  : te::plugin::Plugin(pluginInfo), m_layoutMenu(0)
59 {
60 }
61 
63 {
64 }
65 
67 {
68  if(m_initialized)
69  return;
70 
71 // it initializes the Translator support for the TerraLib LayoutEditor Qt Plugin
73 
74  TE_LOG_TRACE(TE_TR("TerraLib Qt Map Layout Plugin startup!"));
75 
76  // add plugin menu
77  QMenu* pluginMenu = te::qt::af::ApplicationController::getInstance().getMenu("Plugins");
78 
79  if(!pluginMenu)
80  return;
81 
82  // Insert action before plugin manager action
83  QAction* pluginsSeparator = te::qt::af::ApplicationController::getInstance().findAction("ManagePluginsSeparator");
84 
85  if(!pluginsSeparator)
86  return;
87 
88  m_layoutMenu = new QMenu(pluginMenu);
89  m_layoutMenu->setIcon(QIcon::fromTheme("map-layout-icon"));
90 
91  pluginMenu->insertMenu(pluginsSeparator, m_layoutMenu);
92 
93  m_layoutMenu->setTitle(TE_TR("Map Layout"));
94 
95  // register actions
96  registerActions();
97 
98  // layout log startup
99  std::string path = te::qt::af::ApplicationController::getInstance().getUserDataDir().toStdString();
100  path += "/log/terralib_map_layout.log";
101 
102 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
103  std::string layout = "%d{ISO8601} [%t] %-5p %c - %m%n";
104  log4cxx::LogString lString(layout.begin(), layout.end());
105 
106  log4cxx::FileAppender* fileAppender = new log4cxx::RollingFileAppender(log4cxx::LayoutPtr(new log4cxx::PatternLayout(lString)),
107  log4cxx::helpers::Transcoder::decode(path.c_str()), true);
108 
109  log4cxx::helpers::Pool p;
110  fileAppender->activateOptions(p);
111 
112  log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(fileAppender));
113  log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
114 
115  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("maplayout");
116  logger->setAdditivity(false);
117  logger->addAppender(fileAppender);
118 #endif
119  m_initialized = true;
120 }
121 
123 {
124  if(!m_initialized)
125  return;
126 
127  // unregister actions
128  unRegisterActions();
129 
130  // remove menu
131  if(m_layoutMenu)
132  {
133  delete m_layoutMenu;
134  m_layoutMenu = 0;
135  }
136 
137 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
138  log4cxx::LogManager::shutdown();
139 #endif
140 
141  TE_LOG_TRACE(TE_TR("TerraLib Qt Map Layout Plugin shutdown!"));
142 
143  m_initialized = false;
144 }
145 
147 {
148 #ifdef TE_QT_PLUGIN_LAYOUT_HAVE_LAYOUTEDITOR
149  m_layout = new te::qt::plugins::layout::LayoutEditorAction(m_layoutMenu);
150 #endif
151 }
152 
154 {
155 #ifdef TE_QT_PLUGIN_LAYOUT_HAVE_LAYOUTEDITOR
156  if(m_layout)
157  {
158  delete m_layout;
159  m_layout = 0;
160  }
161 #endif
162 }
163 
#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 file defines the Transformation class.
This class register the contrast action into VP Plugin.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
#define TE_QT_PLUGIN_LAYOUT_TEXT_DOMAIN
It contains the name of the text domain used in the translation of messages in TerraLib LAYOUT Qt Plu...
Definition: Config.h:52
~Plugin()
Virtual destructor.
Definition: Plugin.cpp:62
#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
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
void startup()
Do nothing! Just set plugin as started.
Definition: Plugin.cpp:66
#define TE_ADD_TEXT_DOMAIN(domain, domaindir, codeset)
It adds the given text domain located at domain-dir with the given codeset to the multilingual system...
Definition: Translator.h:310
Plugin(const te::plugin::PluginInfo &pluginInfo)
Definition: Plugin.cpp:57
void unRegisterActions()
Function used to unregister all raster processing actions.
Definition: Plugin.cpp:153
void registerActions()
Function used to register all raster processing actions.
Definition: Plugin.cpp:146
bool decode(std::string &s)
Decode the pct-encoded (hex) sequences, if any, return success.
Definition: urisyn.cpp:171
#define TE_QT_PLUGIN_LAYOUT_TEXT_DOMAIN_DIR
It contains the translation catalog directory.
Definition: Config.h:59
void shutdown()
Do nothing! Just set plugin as stopped.
Definition: Plugin.cpp:122
The basic information about a plugin.
Definition: PluginInfo.h:61