1 // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2011 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Winch Gate Property Limited
6 // Copyright (C) 2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU Affero General Public License as
11 // published by the Free Software Foundation, either version 3 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU Affero General Public License for more details.
19 // You should have received a copy of the GNU Affero General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "general_settings_page.h"
24 #include "core_constants.h"
28 #include <nel/misc/path.h>
31 #include <QtCore/QSettings>
32 #include <QtGui/QWidget>
33 #include <QtGui/QMessageBox>
34 #include <QtGui/QFileDialog>
35 #include <QtGui/QStyleFactory>
36 #include <QtGui/QStyle>
45 GeneralSettingsPage::GeneralSettingsPage(QObject
*parent
)
46 : IOptionsPage(parent
),
49 m_originalPalette
= QApplication::palette();
52 GeneralSettingsPage::~GeneralSettingsPage()
56 QString
GeneralSettingsPage::id() const
58 return QLatin1String("general_settings");
61 QString
GeneralSettingsPage::trName() const
66 QString
GeneralSettingsPage::category() const
68 return QLatin1String(Constants::SETTINGS_CATEGORY_GENERAL
);
71 QString
GeneralSettingsPage::trCategory() const
73 return tr(Constants::SETTINGS_TR_CATEGORY_GENERAL
);
76 QIcon
GeneralSettingsPage::categoryIcon() const
81 void GeneralSettingsPage::applyGeneralSettings()
83 QSettings
*settings
= Core::ICore::instance()->settings();
85 settings
->beginGroup(Constants::MAIN_WINDOW_SECTION
);
86 QApplication::setStyle(QStyleFactory::create(settings
->value(Constants::QT_STYLE
, "").toString()));
88 if (settings
->value(Constants::QT_PALETTE
, true).toBool())
89 QApplication::setPalette(QApplication::style()->standardPalette());
91 QApplication::setPalette(m_originalPalette
);
94 QString levelDesignPrefix
;
95 #if defined(_DEBUG) && defined(NL_OS_WINDOWS)
96 levelDesignPrefix
= "l:";
98 levelDesignPrefix
= QString("%1/data_leveldesign").arg(RYZOM_SHARE_PREFIX
);
101 // Add primitives path and ligo config file to CPath
102 settings
->beginGroup(Core::Constants::DATA_PATH_SECTION
);
103 QString primitivePath
= settings
->value(Core::Constants::PRIMITIVES_PATH
, QString("%1/primitives").arg(levelDesignPrefix
)).toString();
104 QString ligoConfigFile
= settings
->value(Core::Constants::LIGOCONFIG_FILE
, QString("%1/leveldesign/world_editor_files/world_editor_classes.xml").arg(levelDesignPrefix
)).toString();
105 QString leveldesignPath
= settings
->value(Core::Constants::LEVELDESIGN_PATH
, QString("%1/leveldesign").arg(levelDesignPrefix
)).toString();
106 NLMISC::CPath::addSearchPath(primitivePath
.toUtf8().constData(), true, false);
107 NLMISC::CPath::display();
108 NLMISC::CPath::addSearchFile(ligoConfigFile
.toUtf8().constData());
109 NLMISC::CPath::addSearchPath(leveldesignPath
.toUtf8().constData(), true, false);
110 settings
->endGroup();
113 QWidget
*GeneralSettingsPage::createPage(QWidget
*parent
)
115 m_page
= new QWidget(parent
);
116 m_ui
.setupUi(m_page
);
119 connect(m_ui
.languageComboBox
, SIGNAL(currentIndexChanged(QString
)), this, SLOT(changeLanguage(QString
)));
120 connect(m_ui
.pluginsPathButton
, SIGNAL(clicked()), this, SLOT(setPluginsPath()));
121 connect(m_ui
.leveldesignPathButton
, SIGNAL(clicked()), this, SLOT(setLevelDesignPath()));
122 connect(m_ui
.assetsPathButton
, SIGNAL(clicked()), this, SLOT(setAssetsPath()));
123 connect(m_ui
.primitivesPathButton
, SIGNAL(clicked()), this, SLOT(setPrimitivesPath()));
124 connect(m_ui
.ligoConfigFileButton
, SIGNAL(clicked()), this, SLOT(setLigoConfigFile()));
128 void GeneralSettingsPage::apply()
131 applyGeneralSettings();
134 void GeneralSettingsPage::finish()
140 void GeneralSettingsPage::changeLanguage(const QString
&lang
)
142 QMessageBox::information(0, tr("Restart required"),
143 tr("The language change will take effect after a restart of Object Viewer Qt."));
146 void GeneralSettingsPage::setPluginsPath()
148 QString newPath
= QFileDialog::getExistingDirectory(0, tr("Set the plugins path"),
149 m_ui
.pluginsPathLineEdit
->text());
150 if (!newPath
.isEmpty())
152 m_ui
.pluginsPathLineEdit
->setText(newPath
);
156 void GeneralSettingsPage::setLevelDesignPath()
158 QString newPath
= QFileDialog::getExistingDirectory(0, tr("Set the level design path"),
159 m_ui
.leveldesignPathLineEdit
->text());
160 if (!newPath
.isEmpty())
162 m_ui
.leveldesignPathLineEdit
->setText(newPath
);
166 void GeneralSettingsPage::setPrimitivesPath()
168 QString newPath
= QFileDialog::getExistingDirectory(0, tr("Set the primitives path"),
169 m_ui
.primitivesPathLineEdit
->text());
170 if (!newPath
.isEmpty())
172 m_ui
.primitivesPathLineEdit
->setText(newPath
);
176 void GeneralSettingsPage::setLigoConfigFile()
178 QString newFile
= QFileDialog::getOpenFileName(0, tr("Set the ligo config file"),
179 m_ui
.ligoConfigFileLineEdit
->text());
180 if (!newFile
.isEmpty())
182 m_ui
.ligoConfigFileLineEdit
->setText(newFile
);
187 void GeneralSettingsPage::setAssetsPath()
189 QString newPath
= QFileDialog::getExistingDirectory(0, tr("Set the assets path"),
190 m_ui
.assetsPathLineEdit
->text());
191 if (!newPath
.isEmpty())
193 m_ui
.assetsPathLineEdit
->setText(newPath
);
197 void GeneralSettingsPage::readSettings()
199 QSettings
*settings
= Core::ICore::instance()->settings();
201 m_ui
.pluginsPathLineEdit
->setText(settings
->value(Core::Constants::PLUGINS_PATH
, "./plugins").toString());
203 settings
->beginGroup(Constants::MAIN_WINDOW_SECTION
);
204 m_ui
.styleComboBox
->addItems(QStyleFactory::keys());
205 QString style
= settings
->value(Constants::QT_STYLE
, "").toString();
207 m_ui
.styleComboBox
->setCurrentIndex(0);
209 m_ui
.styleComboBox
->setCurrentIndex(m_ui
.styleComboBox
->findText(style
));
210 m_ui
.paletteCheckBox
->setChecked(settings
->value(Constants::QT_PALETTE
, true).toBool());
211 settings
->endGroup();
214 settings
->beginGroup(Core::Constants::DATA_PATH_SECTION
);
215 m_ui
.leveldesignPathLineEdit
->setText(settings
->value(Core::Constants::LEVELDESIGN_PATH
, "R:/leveldesign").toString());
216 m_ui
.assetsPathLineEdit
->setText(settings
->value(Core::Constants::ASSETS_PATH
, "R:/graphics").toString());
217 m_ui
.primitivesPathLineEdit
->setText(settings
->value(Core::Constants::PRIMITIVES_PATH
, "R:/leveldesign/primitives").toString());
218 m_ui
.ligoConfigFileLineEdit
->setText(settings
->value(Core::Constants::LIGOCONFIG_FILE
, "R:/leveldesign/world_editor_files/world_editor_classes.xml").toString());
219 settings
->endGroup();
222 void GeneralSettingsPage::writeSettings()
224 QSettings
*settings
= Core::ICore::instance()->settings();
226 settings
->setValue(Core::Constants::PLUGINS_PATH
, m_ui
.pluginsPathLineEdit
->text());
228 settings
->beginGroup(Constants::MAIN_WINDOW_SECTION
);
229 if (m_ui
.styleComboBox
->currentIndex() == 0)
230 settings
->setValue(Constants::QT_STYLE
, "");
232 settings
->setValue(Constants::QT_STYLE
, m_ui
.styleComboBox
->currentText());
233 settings
->setValue(Constants::QT_PALETTE
, m_ui
.paletteCheckBox
->isChecked());
234 settings
->endGroup();
236 settings
->beginGroup(Core::Constants::DATA_PATH_SECTION
);
237 settings
->setValue(Core::Constants::LEVELDESIGN_PATH
, m_ui
.leveldesignPathLineEdit
->text());
238 settings
->setValue(Core::Constants::ASSETS_PATH
, m_ui
.assetsPathLineEdit
->text());
239 settings
->setValue(Core::Constants::PRIMITIVES_PATH
, m_ui
.primitivesPathLineEdit
->text());
240 settings
->setValue(Core::Constants::LIGOCONFIG_FILE
, m_ui
.ligoConfigFileLineEdit
->text());
241 settings
->endGroup();
245 } /* namespace Core */