All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GeneralConfigWidget.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 GeneralConfigWidget.cpp
22 
23  \brief A frame for setting general options.
24 */
25 
26 // TerraLib
27 #include "../../../common/PlatformUtils.h"
28 #include "../../../common/SystemApplicationSettings.h"
29 #include "../../../common/UserApplicationSettings.h"
30 #include "../../../qt/widgets/srs/SRSManagerDialog.h"
31 #include "../../../qt/widgets/utils/ColorPickerToolButton.h"
32 #include "../../../srs/Config.h"
33 #include "../ApplicationController.h"
34 #include "../Utils.h"
35 #include "GeneralConfigWidget.h"
36 #include "ui_GeneralConfigWidgetForm.h"
37 
38 // Qt
39 #include <QDir>
40 #include <QPushButton>
41 #include <QString>
42 
44  : AbstractSettingWidget(parent),
45  m_ui(new Ui::GeneralConfigWidgetForm),
46  m_defaultSRID(TE_UNKNOWN_SRS),
47  m_needRestart(false)
48 {
49  m_resumeText = tr("Changes the general configurations of the application.");
50 
51  m_ui->setupUi(this);
52 
53  initialize();
54 }
55 
57 {
58  if(m_needRestart)
59  {
60  QMessageBox msgBox(this);
61 
62  msgBox.setText(tr("The system must be restarted for the changes to take effect."));
63  msgBox.setInformativeText(tr("Do you want to do it now?"));
64  msgBox.setWindowTitle(tr("Restart system"));
65 
66  std::auto_ptr<QPushButton> restartButton;
67  restartButton.reset(msgBox.addButton(tr("Restart now"), QMessageBox::ActionRole));
68 
69  std::auto_ptr<QPushButton> laterResButton;
70  laterResButton.reset(msgBox.addButton(tr("Restart later"), QMessageBox::DestructiveRole));
71  msgBox.addButton(QMessageBox::NoButton);
72 
73  msgBox.setDefaultButton(restartButton.get());
74 
75  msgBox.exec();
76 
77  if(msgBox.clickedButton() == restartButton.get())
78  qApp->exit(1000);
79  }
80 }
81 
83 {
84  QSettings settings(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
85 
86  settings.setValue("srs/default_srid", m_defaultSRID);
87  settings.setValue("color/selection_color", m_colorPicker->getColor().name());
88  settings.setValue("toolbars/icon_size", m_ui->m_toolBarIconSizeSpinBox->value());
89  settings.setValue("icon_theme/selected_theme", m_ui->m_iconThemeComboBox->currentText());
90 
91  ApplicationController::getInstance().setSelectionColor(m_colorPicker->getColor());
92 
93  changeApplyButtonState(false);
94 }
95 
97 {
98 }
99 
100 void te::qt::af::GeneralConfigWidget::getHelpInformations(QString& ns, QString& helpFile)
101 {
102  ns = "dpi.inpe.br.apf";
103  helpFile = "apf/settings/generalconfig/GeneralConfig.html";
104 }
105 
107 {
108  // Setup UI icons
109  m_ui->m_defaultSRSToolButton->setIcon(QIcon::fromTheme("srs"));
110 
111  // Create Color Picker to selection color
112  m_colorPicker = new te::qt::widgets::ColorPickerToolButton(this);
113  m_colorPicker->setFixedSize(70, 24);
114 
115  // Adjusting color picker...
116  QGridLayout* layout = new QGridLayout(m_ui->m_selectionColorFrame);
117  layout->setContentsMargins(0, 0, 0, 0);
118  layout->setSizeConstraint(QLayout::SetFixedSize);
119  layout->addWidget(m_colorPicker);
120 
121  // Get user settings
122  QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::instance()->organizationName(), QApplication::instance()->applicationName());
123 
124  // SRID
125  m_defaultSRID = settings.value("srs/default_srid", te::common::SystemApplicationSettings::getInstance().getValue("Application.DefaultSRID").c_str()).toInt();
126  setupSRSUi();
127 
128  // Selection Color
129  QString selectionColorName = settings.value("color/selection_color", te::common::SystemApplicationSettings::getInstance().getValue("Application.DefaultSelectionColor").c_str()).toString();
130  QColor selectionColor = QColor(selectionColorName);
131  m_colorPicker->setColor(selectionColor);
132 
133  // ToolBar Icon Size
134  int iconSize = settings.value("toolbars/icon_size", te::common::SystemApplicationSettings::getInstance().getValue("Application.ToolBarDefaultIconSize").c_str()).toInt();
135  m_ui->m_toolBarIconSizeSpinBox->setValue(iconSize);
136 
137  // Icon Theme
138  std::string iconThemesDirPath = te::common::FindInTerraLibPath(te::common::SystemApplicationSettings::getInstance().getValue("Application.IconThemeInfo.BaseDirectory.<xmlattr>.xlink:href"));
139  QDir iconThemesDir(iconThemesDirPath.c_str());
140 
141  // Find themes
142  QStringList themes = iconThemesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
143  m_ui->m_iconThemeComboBox->clear();
144  m_ui->m_iconThemeComboBox->addItems(themes);
145 
146  // Signals & slots
147  connect(m_ui->m_defaultSRSToolButton, SIGNAL(pressed()), SLOT(onDefaultSRSToolButtonPressed()));
148  connect(m_colorPicker, SIGNAL(colorChanged(const QColor&)), SLOT(onSelectionColorChanged(const QColor&)));
149  connect(m_ui->m_toolBarIconSizeSpinBox, SIGNAL(valueChanged(int)), SLOT(onToolBarIconSizeValueChanged(int)));
150  connect(m_ui->m_iconThemeComboBox, SIGNAL(currentIndexChanged(const QString&)), SLOT(onIconThemeCurrentIndexChanged(const QString&)));
151 }
152 
154 {
155  m_defaultSRID != TE_UNKNOWN_SRS ? m_ui->m_defaultSRSLineEdit->setText("EPSG:" + QString::number(m_defaultSRID)) : m_ui->m_defaultSRSLineEdit->setText(tr("Unknown SRS"));
156 }
157 
159 {
160  te::qt::widgets::SRSManagerDialog srsDialog(this);
161  srsDialog.setWindowTitle(tr("Choose the Default SRS"));
162 
163  if(srsDialog.exec() == QDialog::Rejected)
164  return;
165 
166  m_defaultSRID = srsDialog.getSelectedSRS().first;
167 
168  setupSRSUi();
169 
170  changeApplyButtonState(true);
171 }
172 
174 {
175  changeApplyButtonState(true);
176 }
177 
179 {
180  m_needRestart = true;
181  changeApplyButtonState(true);
182 }
183 
185 {
186  m_needRestart = true;
187  changeApplyButtonState(true);
188 }
void onIconThemeCurrentIndexChanged(const QString &value)
TECOMMONEXPORT std::string FindInTerraLibPath(const std::string &p)
Returns the path relative to a directory or file in the context of TerraLib.
A frame for setting general options.
Custom tool button used to pick a color.
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
void getHelpInformations(QString &ns, QString &helpFile)
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:44
A frame for setting Table options.
void setSelectionColor(const QColor &c)
Sets the application selection color.
std::auto_ptr< Ui::GeneralConfigWidgetForm > m_ui
A dialog used to build a SRSManagerDialog element.
const std::pair< int, std::string > & getSelectedSRS() const
Returns the selected SRS in the window.
void onSelectionColorChanged(const QColor &color)