33 #include <QMainWindow>
34 #include <QMessageBox>
35 #include <QtCore/QDir>
36 #include <QtCore/QLibraryInfo>
37 #include <QtCore/QSettings>
39 #include "ui_generalsettings.h"
41 using namespace Core::Internal;
44 : m_saveSettingsOnExit(true)
47 , m_useExpertMode(false)
49 , m_proxyType(QNetworkProxy::NoProxy)
56 return QLatin1String(
"General");
66 return QLatin1String(
"Environment");
71 return tr(
"Environment");
74 static bool hasQmFilesForLocale(
const QString &locale,
const QString &creatorTrPath)
76 static const QString qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
78 const QString trFile = QLatin1String(
"qt_") + locale + QLatin1String(
".qm");
79 return QFile::exists(qtTrPath +
'/' + trFile) || QFile::exists(creatorTrPath +
'/' + trFile);
82 void GeneralSettings::fillLanguageBox()
const
84 const QString currentLocale = language();
86 m_page->languageBox->addItem(tr(
"<System Language>"), QString());
88 m_page->languageBox->addItem(QLatin1String(
"English"), QLatin1String(
"C"));
89 if (currentLocale == QLatin1String(
"C"))
90 m_page->languageBox->setCurrentIndex(m_page->languageBox->count() - 1);
92 const QString creatorTrPath =
94 const QStringList languageFiles =
95 QDir(creatorTrPath).entryList(QStringList(QLatin1String(
"dronin*.qm")));
97 Q_FOREACH (
const QString &languageFile, languageFiles) {
98 int start = languageFile.indexOf(QLatin1Char(
'_')) + 1;
99 int end = languageFile.lastIndexOf(QLatin1Char(
'.'));
100 const QString locale = languageFile.mid(start, end - start);
102 if (hasQmFilesForLocale(locale, creatorTrPath)) {
103 m_page->languageBox->addItem(QLocale::languageToString(QLocale(locale).language()),
105 if (locale == currentLocale)
106 m_page->languageBox->setCurrentIndex(m_page->languageBox->count() - 1);
111 void GeneralSettings::fillProxyTypesBox()
const
113 m_page->proxyTypeCB->addItem(
"No Proxy", 2);
114 m_page->proxyTypeCB->addItem(
"Socks5Proxy", 1);
115 m_page->proxyTypeCB->addItem(
"HttpProxy", 3);
116 m_page->proxyTypeCB->addItem(
"HttpCachingProxy", 4);
117 m_page->proxyTypeCB->addItem(
"FtpCachingProxy", 5);
122 m_page =
new Ui::GeneralSettings();
123 QWidget *w =
new QWidget(parent);
127 connect(m_page->checkAutoConnect, SIGNAL(stateChanged(
int)),
this, SLOT(slotAutoConnect(
int)));
128 m_page->checkBoxSaveOnExit->setChecked(m_saveSettingsOnExit);
129 m_page->checkAutoConnect->setChecked(m_autoConnect);
130 m_page->checkAutoSelect->setChecked(m_autoSelect);
131 m_page->cbExpertMode->setChecked(m_useExpertMode);
132 m_page->proxyTypeCB->setCurrentIndex(m_page->proxyTypeCB->findData(m_proxyType));
133 m_page->portLE->setText(QString::number(m_proxyPort));
134 m_page->hostNameLE->setText(m_proxyHostname);
135 m_page->userLE->setText(m_proxyUser);
136 m_page->passwordLE->setText(m_proxyPassword);
143 int currentIndex = m_page->languageBox->currentIndex();
144 setLanguage(m_page->languageBox->itemData(currentIndex, Qt::UserRole).toString());
147 m_saveSettingsOnExit = m_page->checkBoxSaveOnExit->isChecked();
148 m_useExpertMode = m_page->cbExpertMode->isChecked();
149 m_autoConnect = m_page->checkAutoConnect->isChecked();
150 m_autoSelect = m_page->checkAutoSelect->isChecked();
151 m_proxyType = m_page->proxyTypeCB->itemData(m_page->proxyTypeCB->currentIndex()).toInt();
152 m_proxyPort = m_page->portLE->text().toInt();
153 m_proxyHostname = m_page->hostNameLE->text();
154 m_proxyUser = m_page->userLE->text();
155 m_proxyPassword = m_page->passwordLE->text();
167 qs->beginGroup(QLatin1String(
"General"));
168 m_language = qs->value(QLatin1String(
"OverrideLanguage"), QLocale::system().name()).toString();
169 m_saveSettingsOnExit =
170 qs->value(QLatin1String(
"SaveSettingsOnExit"), m_saveSettingsOnExit).toBool();
171 m_autoConnect = qs->value(QLatin1String(
"AutoConnect"), m_autoConnect).toBool();
172 m_autoSelect = qs->value(QLatin1String(
"AutoSelect"), m_autoSelect).toBool();
173 m_useExpertMode = qs->value(QLatin1String(
"ExpertMode"), m_useExpertMode).toBool();
174 m_proxyType = qs->value(QLatin1String(
"proxytype"), m_proxyType).toInt();
175 m_proxyPort = qs->value(QLatin1String(
"proxyport"), m_proxyPort).toInt();
176 m_proxyHostname = qs->value(QLatin1String(
"proxyhostname"), m_proxyHostname).toString();
177 m_proxyUser = qs->value(QLatin1String(
"proxyuser"), m_proxyUser).toString();
178 m_proxyPassword = qs->value(QLatin1String(
"proxypassword"), m_proxyPassword).toString();
179 m_observations = qs->value(QLatin1String(
"observations"),
"").toString();
180 m_vehicle = qs->value(QLatin1String(
"vehicle"),
"").toString();
181 m_board = qs->value(QLatin1String(
"board"),
"").toString();
182 m_weight = qs->value(QLatin1String(
"weight"), 0).toInt();
183 m_size = qs->value(QLatin1String(
"size"), 0).toInt();
184 m_cells = qs->value(QLatin1String(
"cells"), 0).toInt();
185 m_motors = qs->value(QLatin1String(
"motors"),
"").toString();
186 m_escs = qs->value(QLatin1String(
"escs"),
"").toString();
187 m_props = qs->value(QLatin1String(
"props"),
"").toString();
194 qs->beginGroup(QLatin1String(
"General"));
196 if (m_language.isEmpty())
197 qs->remove(QLatin1String(
"OverrideLanguage"));
199 qs->setValue(QLatin1String(
"OverrideLanguage"), m_language);
201 qs->setValue(QLatin1String(
"SaveSettingsOnExit"), m_saveSettingsOnExit);
202 qs->setValue(QLatin1String(
"AutoConnect"), m_autoConnect);
203 qs->setValue(QLatin1String(
"AutoSelect"), m_autoSelect);
204 qs->setValue(QLatin1String(
"ExpertMode"), m_useExpertMode);
206 qs->setValue(QLatin1String(
"proxytype"), m_proxyType);
207 qs->setValue(QLatin1String(
"proxyport"), m_proxyPort);
208 qs->setValue(QLatin1String(
"proxyhostname"), m_proxyHostname);
209 qs->setValue(QLatin1String(
"proxyuser"), m_proxyUser);
210 qs->setValue(QLatin1String(
"proxypassword"), m_proxyPassword);
211 qs->setValue(QLatin1String(
"observations"), m_observations);
212 qs->setValue(QLatin1String(
"vehicle"), m_vehicle);
213 qs->setValue(QLatin1String(
"board"), m_board);
214 qs->setValue(QLatin1String(
"weight"), m_weight);
215 qs->setValue(QLatin1String(
"size"), m_size);
216 qs->setValue(QLatin1String(
"cells"), m_cells);
217 qs->setValue(QLatin1String(
"motors"), m_motors);
218 qs->setValue(QLatin1String(
"escs"), m_escs);
219 qs->setValue(QLatin1String(
"props"), m_props);
223 void GeneralSettings::showHelpForExternalEditor()
228 m_dialog->activateWindow();
233 void GeneralSettings::resetLanguage()
236 m_page->languageBox->setCurrentIndex(0);
239 QString GeneralSettings::language()
const
244 void GeneralSettings::setLanguage(
const QString &locale)
246 if (m_language != locale) {
247 if (!locale.isEmpty()) {
248 QMessageBox::information(
250 tr(
"Restart required"),
251 tr(
"The language change will take effect after a restart of the GCS."));
259 return m_saveSettingsOnExit;
264 return m_autoConnect;
274 return m_useExpertMode;
279 return QNetworkProxy((QNetworkProxy::ProxyType)m_proxyType, m_proxyHostname, m_proxyPort,
280 m_proxyUser, m_proxyPassword);
285 m_observations = value;
295 return m_observations;
373 void GeneralSettings::slotAutoConnect(
int value)
375 if (value == Qt::Checked)
376 m_page->checkAutoSelect->setEnabled(
false);
378 m_page->checkAutoSelect->setEnabled(
true);
void setMotors(QString motors)
void setWeight(int weight)
void setBatteryCells(int cells)
void setProps(QString props)
bool saveSettingsOnExit() const
virtual QString resourcePath() const =0
Returns the absolute path that is used for resources like project templates and the debugger macros...
void setESCs(QString escs)
void setVehicleSize(int spacing)
void generalSettingsChanged()
void saveSettings(QSettings *qs)
QString getObservations()
void readSettings(QSettings *qs)
end(INSTANTIATIONCODE) fid
static ICore * instance()
QString trCategory() const
QWidget * createPage(QWidget *parent)
void setVehicleType(QString type)
void setBoardType(QString type)
QNetworkProxy getNetworkProxy()
bool useExpertMode() const
void setObservations(QString value)