]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include "config.h" | |
21 | ||
22 | #include <glib.h> | |
23 | #include <boost/version.hpp> | |
24 | ||
25 | #include <QApplication> | |
26 | #include <QComboBox> | |
27 | #include <QDialogButtonBox> | |
28 | #include <QFileDialog> | |
29 | #include <QFormLayout> | |
30 | #include <QGroupBox> | |
31 | #include <QHBoxLayout> | |
32 | #include <QLabel> | |
33 | #include <QMainWindow> | |
34 | #include <QMessageBox> | |
35 | #include <QPushButton> | |
36 | #include <QScrollBar> | |
37 | #include <QSpinBox> | |
38 | #include <QString> | |
39 | #include <QTextBrowser> | |
40 | #include <QTextDocument> | |
41 | #include <QTextStream> | |
42 | #include <QVBoxLayout> | |
43 | ||
44 | #include "settings.hpp" | |
45 | ||
46 | #include "pv/devicemanager.hpp" | |
47 | #include "pv/globalsettings.hpp" | |
48 | #include "pv/logging.hpp" | |
49 | ||
50 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
51 | ||
52 | #ifdef ENABLE_DECODE | |
53 | #include <libsigrokdecode/libsigrokdecode.h> | |
54 | #endif | |
55 | ||
56 | using std::shared_ptr; | |
57 | ||
58 | namespace pv { | |
59 | namespace dialogs { | |
60 | ||
61 | /** | |
62 | * Special version of a QListView that has the width of the first column as minimum size. | |
63 | * | |
64 | * @note Inspired by https://github.com/qt-creator/qt-creator/blob/master/src/plugins/coreplugin/dialogs/settingsdialog.cpp | |
65 | */ | |
66 | class PageListWidget: public QListWidget | |
67 | { | |
68 | public: | |
69 | PageListWidget() : | |
70 | QListWidget() | |
71 | { | |
72 | setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); | |
73 | } | |
74 | ||
75 | QSize sizeHint() const final | |
76 | { | |
77 | int width = sizeHintForColumn(0) + frameWidth() * 2 + 5; | |
78 | if (verticalScrollBar()->isVisible()) | |
79 | width += verticalScrollBar()->width(); | |
80 | return QSize(width, 100); | |
81 | } | |
82 | }; | |
83 | ||
84 | Settings::Settings(DeviceManager &device_manager, QWidget *parent) : | |
85 | QDialog(parent, nullptr), | |
86 | device_manager_(device_manager) | |
87 | { | |
88 | resize(600, 400); | |
89 | ||
90 | // Create log view | |
91 | log_view_ = create_log_view(); | |
92 | ||
93 | // Create pages | |
94 | page_list = new PageListWidget(); | |
95 | page_list->setViewMode(QListView::ListMode); | |
96 | page_list->setMovement(QListView::Static); | |
97 | page_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
98 | ||
99 | pages = new QStackedWidget; | |
100 | create_pages(); | |
101 | page_list->setCurrentIndex(page_list->model()->index(0, 0)); | |
102 | ||
103 | // Create the rest of the dialog | |
104 | QHBoxLayout *tab_layout = new QHBoxLayout; | |
105 | tab_layout->addWidget(page_list); | |
106 | tab_layout->addWidget(pages, Qt::AlignLeft); | |
107 | ||
108 | QDialogButtonBox *button_box = new QDialogButtonBox( | |
109 | QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | |
110 | ||
111 | QVBoxLayout* root_layout = new QVBoxLayout(this); | |
112 | root_layout->addLayout(tab_layout); | |
113 | root_layout->addWidget(button_box); | |
114 | ||
115 | connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); | |
116 | connect(button_box, SIGNAL(rejected()), this, SLOT(reject())); | |
117 | connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), | |
118 | this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*))); | |
119 | ||
120 | // Start to record changes | |
121 | GlobalSettings settings; | |
122 | settings.start_tracking(); | |
123 | } | |
124 | ||
125 | void Settings::create_pages() | |
126 | { | |
127 | // View page | |
128 | pages->addWidget(get_view_settings_form(pages)); | |
129 | ||
130 | QListWidgetItem *viewButton = new QListWidgetItem(page_list); | |
131 | viewButton->setIcon(QIcon(":/icons/settings-views.svg")); | |
132 | viewButton->setText(tr("Views")); | |
133 | viewButton->setTextAlignment(Qt::AlignVCenter); | |
134 | viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
135 | ||
136 | #ifdef ENABLE_DECODE | |
137 | // Decoder page | |
138 | pages->addWidget(get_decoder_settings_form(pages)); | |
139 | ||
140 | QListWidgetItem *decoderButton = new QListWidgetItem(page_list); | |
141 | decoderButton->setIcon(QIcon(":/icons/add-decoder.svg")); | |
142 | decoderButton->setText(tr("Decoders")); | |
143 | decoderButton->setTextAlignment(Qt::AlignVCenter); | |
144 | decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
145 | #endif | |
146 | ||
147 | // About page | |
148 | pages->addWidget(get_about_page(pages)); | |
149 | ||
150 | QListWidgetItem *aboutButton = new QListWidgetItem(page_list); | |
151 | aboutButton->setIcon(QIcon(":/icons/information.svg")); | |
152 | aboutButton->setText(tr("About")); | |
153 | aboutButton->setTextAlignment(Qt::AlignVCenter); | |
154 | aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
155 | ||
156 | // Logging page | |
157 | pages->addWidget(get_logging_page(pages)); | |
158 | ||
159 | QListWidgetItem *loggingButton = new QListWidgetItem(page_list); | |
160 | loggingButton->setIcon(QIcon(":/icons/information.svg")); | |
161 | loggingButton->setText(tr("Logging")); | |
162 | loggingButton->setTextAlignment(Qt::AlignVCenter); | |
163 | loggingButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
164 | } | |
165 | ||
166 | QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const | |
167 | { | |
168 | GlobalSettings settings; | |
169 | ||
170 | QCheckBox *cb = new QCheckBox(); | |
171 | cb->setChecked(settings.value(key).toBool()); | |
172 | connect(cb, SIGNAL(stateChanged(int)), this, slot); | |
173 | return cb; | |
174 | } | |
175 | ||
176 | QPlainTextEdit *Settings::create_log_view() const | |
177 | { | |
178 | GlobalSettings settings; | |
179 | ||
180 | QPlainTextEdit *log_view = new QPlainTextEdit(); | |
181 | ||
182 | log_view->setReadOnly(true); | |
183 | log_view->setWordWrapMode(QTextOption::NoWrap); | |
184 | log_view->setCenterOnScroll(true); | |
185 | ||
186 | log_view->appendHtml(logging.get_log()); | |
187 | connect(&logging, SIGNAL(logged_text(QString)), | |
188 | log_view, SLOT(appendHtml(QString))); | |
189 | ||
190 | return log_view; | |
191 | } | |
192 | ||
193 | QWidget *Settings::get_view_settings_form(QWidget *parent) const | |
194 | { | |
195 | GlobalSettings settings; | |
196 | QCheckBox *cb; | |
197 | ||
198 | QWidget *form = new QWidget(parent); | |
199 | QVBoxLayout *form_layout = new QVBoxLayout(form); | |
200 | ||
201 | // Trace view settings | |
202 | QGroupBox *trace_view_group = new QGroupBox(tr("Trace View")); | |
203 | form_layout->addWidget(trace_view_group); | |
204 | ||
205 | QFormLayout *trace_view_layout = new QFormLayout(); | |
206 | trace_view_group->setLayout(trace_view_layout); | |
207 | ||
208 | cb = create_checkbox(GlobalSettings::Key_View_ColoredBG, | |
209 | SLOT(on_view_coloredBG_changed(int))); | |
210 | trace_view_layout->addRow(tr("Use colored trace &background"), cb); | |
211 | ||
212 | cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq, | |
213 | SLOT(on_view_zoomToFitDuringAcq_changed(int))); | |
214 | trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb); | |
215 | ||
216 | cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq, | |
217 | SLOT(on_view_zoomToFitAfterAcq_changed(int))); | |
218 | trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb); | |
219 | ||
220 | cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime, | |
221 | SLOT(on_view_triggerIsZero_changed(int))); | |
222 | trace_view_layout->addRow(tr("Show time zero at the trigger"), cb); | |
223 | ||
224 | cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling, | |
225 | SLOT(on_view_stickyScrolling_changed(int))); | |
226 | trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb); | |
227 | ||
228 | cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints, | |
229 | SLOT(on_view_showSamplingPoints_changed(int))); | |
230 | trace_view_layout->addRow(tr("Show data &sampling points"), cb); | |
231 | ||
232 | cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid, | |
233 | SLOT(on_view_showAnalogMinorGrid_changed(int))); | |
234 | trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb); | |
235 | ||
236 | cb = create_checkbox(GlobalSettings::Key_View_ShowHoverMarker, | |
237 | SLOT(on_view_showHoverMarker_changed(int))); | |
238 | trace_view_layout->addRow(tr("Highlight mouse cursor using a vertical marker line"), cb); | |
239 | ||
240 | QSpinBox *snap_distance_sb = new QSpinBox(); | |
241 | snap_distance_sb->setRange(0, 1000); | |
242 | snap_distance_sb->setSuffix(tr(" pixels")); | |
243 | snap_distance_sb->setValue( | |
244 | settings.value(GlobalSettings::Key_View_SnapDistance).toInt()); | |
245 | connect(snap_distance_sb, SIGNAL(valueChanged(int)), this, | |
246 | SLOT(on_view_snapDistance_changed(int))); | |
247 | trace_view_layout->addRow(tr("Maximum distance from edges before cursors snap to them"), snap_distance_sb); | |
248 | ||
249 | QComboBox *thr_disp_mode_cb = new QComboBox(); | |
250 | thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None); | |
251 | thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background); | |
252 | thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots); | |
253 | thr_disp_mode_cb->setCurrentIndex( | |
254 | settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt()); | |
255 | connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)), | |
256 | this, SLOT(on_view_conversionThresholdDispMode_changed(int))); | |
257 | trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb); | |
258 | ||
259 | QSpinBox *default_div_height_sb = new QSpinBox(); | |
260 | default_div_height_sb->setRange(20, 1000); | |
261 | default_div_height_sb->setSuffix(tr(" pixels")); | |
262 | default_div_height_sb->setValue( | |
263 | settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt()); | |
264 | connect(default_div_height_sb, SIGNAL(valueChanged(int)), this, | |
265 | SLOT(on_view_defaultDivHeight_changed(int))); | |
266 | trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb); | |
267 | ||
268 | QSpinBox *default_logic_height_sb = new QSpinBox(); | |
269 | default_logic_height_sb->setRange(5, 1000); | |
270 | default_logic_height_sb->setSuffix(tr(" pixels")); | |
271 | default_logic_height_sb->setValue( | |
272 | settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt()); | |
273 | connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this, | |
274 | SLOT(on_view_defaultLogicHeight_changed(int))); | |
275 | trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb); | |
276 | ||
277 | return form; | |
278 | } | |
279 | ||
280 | QWidget *Settings::get_decoder_settings_form(QWidget *parent) | |
281 | { | |
282 | #ifdef ENABLE_DECODE | |
283 | GlobalSettings settings; | |
284 | QCheckBox *cb; | |
285 | ||
286 | QWidget *form = new QWidget(parent); | |
287 | QVBoxLayout *form_layout = new QVBoxLayout(form); | |
288 | ||
289 | // Decoder settings | |
290 | QGroupBox *decoder_group = new QGroupBox(tr("Decoders")); | |
291 | form_layout->addWidget(decoder_group); | |
292 | ||
293 | QFormLayout *decoder_layout = new QFormLayout(); | |
294 | decoder_group->setLayout(decoder_layout); | |
295 | ||
296 | cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable, | |
297 | SLOT(on_dec_initialStateConfigurable_changed(int))); | |
298 | decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb); | |
299 | ||
300 | // Annotation export settings | |
301 | ann_export_format_ = new QLineEdit(); | |
302 | ann_export_format_->setText( | |
303 | settings.value(GlobalSettings::Key_Dec_ExportFormat).toString()); | |
304 | connect(ann_export_format_, SIGNAL(textChanged(const QString&)), | |
305 | this, SLOT(on_dec_exportFormat_changed(const QString&))); | |
306 | decoder_layout->addRow(tr("Annotation export format"), ann_export_format_); | |
307 | QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %c: row name; %q: use quotations marks")); | |
308 | description_1->setAlignment(Qt::AlignRight); | |
309 | decoder_layout->addRow(description_1); | |
310 | QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts")); | |
311 | description_2->setAlignment(Qt::AlignRight); | |
312 | decoder_layout->addRow(description_2); | |
313 | ||
314 | return form; | |
315 | #else | |
316 | (void)parent; | |
317 | return nullptr; | |
318 | #endif | |
319 | } | |
320 | ||
321 | #ifdef ENABLE_DECODE | |
322 | static gint sort_pds(gconstpointer a, gconstpointer b) | |
323 | { | |
324 | const struct srd_decoder *sda, *sdb; | |
325 | ||
326 | sda = (const struct srd_decoder *)a; | |
327 | sdb = (const struct srd_decoder *)b; | |
328 | return strcmp(sda->id, sdb->id); | |
329 | } | |
330 | #endif | |
331 | ||
332 | QWidget *Settings::get_about_page(QWidget *parent) const | |
333 | { | |
334 | #ifdef ENABLE_DECODE | |
335 | struct srd_decoder *dec; | |
336 | #endif | |
337 | ||
338 | QLabel *icon = new QLabel(); | |
339 | icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg"))); | |
340 | ||
341 | /* Setup the license field, with the project homepage link. */ | |
342 | QLabel *gpl_home_info = new QLabel(); | |
343 | gpl_home_info->setText(tr("%1<br /><a href=\"http://%2\">%2</a>").arg( | |
344 | tr("GNU GPL, version 3 or later"), | |
345 | QApplication::organizationDomain())); | |
346 | gpl_home_info->setOpenExternalLinks(true); | |
347 | ||
348 | shared_ptr<sigrok::Context> context = device_manager_.context(); | |
349 | ||
350 | QString s; | |
351 | ||
352 | s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>"); | |
353 | ||
354 | s.append("<table>"); | |
355 | ||
356 | /* Version, library, and feature info */ | |
357 | s.append("<tr><td colspan=\"2\"><b>" + | |
358 | tr("Versions, libraries and features:") + "</b></td></tr>"); | |
359 | ||
360 | s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>") | |
361 | .arg(QApplication::applicationName(), | |
362 | QApplication::applicationVersion())); | |
363 | s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>") | |
364 | .arg(QString("Qt"), qVersion())); | |
365 | s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>") | |
366 | .arg(QString("glibmm"), PV_GLIBMM_VERSION)); | |
367 | s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>") | |
368 | .arg(QString("Boost"), BOOST_LIB_VERSION)); | |
369 | ||
370 | s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>") | |
371 | .arg(QString("libsigrok"), SR_PACKAGE_VERSION_STRING, | |
372 | SR_LIB_VERSION_STRING, sr_package_version_string_get(), | |
373 | sr_lib_version_string_get())); | |
374 | ||
375 | GSList *l_orig = sr_buildinfo_libs_get(); | |
376 | for (GSList *l = l_orig; l; l = l->next) { | |
377 | GSList *m = (GSList *)l->data; | |
378 | const char *lib = (const char *)m->data; | |
379 | const char *version = (const char *)m->next->data; | |
380 | s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>") | |
381 | .arg(QString(lib), QString(version))); | |
382 | g_slist_free_full(m, g_free); | |
383 | } | |
384 | g_slist_free(l_orig); | |
385 | ||
386 | char *host = sr_buildinfo_host_get(); | |
387 | s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>") | |
388 | .arg(QString(host))); | |
389 | g_free(host); | |
390 | ||
391 | char *scpi_backends = sr_buildinfo_scpi_backends_get(); | |
392 | s.append(QString("<tr><td><i>- SCPI backends</i></td><td>%1</td></tr>") | |
393 | .arg(QString(scpi_backends))); | |
394 | g_free(scpi_backends); | |
395 | ||
396 | #ifdef ENABLE_DECODE | |
397 | s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>") | |
398 | .arg(QString("libsigrokdecode"), SRD_PACKAGE_VERSION_STRING, | |
399 | SRD_LIB_VERSION_STRING, srd_package_version_string_get(), | |
400 | srd_lib_version_string_get())); | |
401 | ||
402 | l_orig = srd_buildinfo_libs_get(); | |
403 | for (GSList *l = l_orig; l; l = l->next) { | |
404 | GSList *m = (GSList *)l->data; | |
405 | const char *lib = (const char *)m->data; | |
406 | const char *version = (const char *)m->next->data; | |
407 | s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>") | |
408 | .arg(QString(lib), QString(version))); | |
409 | g_slist_free_full(m, g_free); | |
410 | } | |
411 | g_slist_free(l_orig); | |
412 | ||
413 | host = srd_buildinfo_host_get(); | |
414 | s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>") | |
415 | .arg(QString(host))); | |
416 | g_free(host); | |
417 | #endif | |
418 | ||
419 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
420 | s.append("<tr><td colspan=\"2\"><b>" + | |
421 | tr("Firmware search paths:") + "</b></td></tr>"); | |
422 | ||
423 | l_orig = sr_resourcepaths_get(SR_RESOURCE_FIRMWARE); | |
424 | for (GSList *l = l_orig; l; l = l->next) | |
425 | s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg( | |
426 | QString((char*)l->data))); | |
427 | g_slist_free_full(l_orig, g_free); | |
428 | ||
429 | #ifdef ENABLE_DECODE | |
430 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
431 | s.append("<tr><td colspan=\"2\"><b>" + | |
432 | tr("Protocol decoder search paths:") + "</b></td></tr>"); | |
433 | ||
434 | l_orig = srd_searchpaths_get(); | |
435 | for (GSList *l = l_orig; l; l = l->next) | |
436 | s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg( | |
437 | QString((char*)l->data))); | |
438 | g_slist_free_full(l_orig, g_free); | |
439 | #endif | |
440 | ||
441 | /* Set up the supported field */ | |
442 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
443 | s.append("<tr><td colspan=\"2\"><b>" + | |
444 | tr("Supported hardware drivers:") + "</b></td></tr>"); | |
445 | for (auto entry : context->drivers()) { | |
446 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") | |
447 | .arg(QString::fromUtf8(entry.first.c_str()), | |
448 | QString::fromUtf8(entry.second->long_name().c_str()))); | |
449 | } | |
450 | ||
451 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
452 | s.append("<tr><td colspan=\"2\"><b>" + | |
453 | tr("Supported input formats:") + "</b></td></tr>"); | |
454 | for (auto entry : context->input_formats()) { | |
455 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") | |
456 | .arg(QString::fromUtf8(entry.first.c_str()), | |
457 | QString::fromUtf8(entry.second->description().c_str()))); | |
458 | } | |
459 | ||
460 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
461 | s.append("<tr><td colspan=\"2\"><b>" + | |
462 | tr("Supported output formats:") + "</b></td></tr>"); | |
463 | for (auto entry : context->output_formats()) { | |
464 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") | |
465 | .arg(QString::fromUtf8(entry.first.c_str()), | |
466 | QString::fromUtf8(entry.second->description().c_str()))); | |
467 | } | |
468 | ||
469 | #ifdef ENABLE_DECODE | |
470 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
471 | s.append("<tr><td colspan=\"2\"><b>" + | |
472 | tr("Supported protocol decoders:") + "</b></td></tr>"); | |
473 | GSList *sl = g_slist_copy((GSList *)srd_decoder_list()); | |
474 | sl = g_slist_sort(sl, sort_pds); | |
475 | for (const GSList *l = sl; l; l = l->next) { | |
476 | dec = (struct srd_decoder *)l->data; | |
477 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") | |
478 | .arg(QString::fromUtf8(dec->id), | |
479 | QString::fromUtf8(dec->longname))); | |
480 | } | |
481 | g_slist_free(sl); | |
482 | #endif | |
483 | ||
484 | s.append("</table>"); | |
485 | ||
486 | QTextDocument *supported_doc = new QTextDocument(); | |
487 | supported_doc->setHtml(s); | |
488 | ||
489 | QTextBrowser *support_list = new QTextBrowser(); | |
490 | support_list->setDocument(supported_doc); | |
491 | ||
492 | QHBoxLayout *h_layout = new QHBoxLayout(); | |
493 | h_layout->setAlignment(Qt::AlignLeft); | |
494 | h_layout->addWidget(icon); | |
495 | h_layout->addWidget(gpl_home_info); | |
496 | ||
497 | QVBoxLayout *layout = new QVBoxLayout(); | |
498 | layout->addLayout(h_layout); | |
499 | layout->addWidget(support_list); | |
500 | ||
501 | QWidget *page = new QWidget(parent); | |
502 | page->setLayout(layout); | |
503 | ||
504 | return page; | |
505 | } | |
506 | ||
507 | QWidget *Settings::get_logging_page(QWidget *parent) const | |
508 | { | |
509 | GlobalSettings settings; | |
510 | ||
511 | // Log level | |
512 | QSpinBox *loglevel_sb = new QSpinBox(); | |
513 | loglevel_sb->setMaximum(SR_LOG_SPEW); | |
514 | loglevel_sb->setValue(logging.get_log_level()); | |
515 | connect(loglevel_sb, SIGNAL(valueChanged(int)), this, | |
516 | SLOT(on_log_logLevel_changed(int))); | |
517 | ||
518 | QHBoxLayout *loglevel_layout = new QHBoxLayout(); | |
519 | loglevel_layout->addWidget(new QLabel(tr("Log level:"))); | |
520 | loglevel_layout->addWidget(loglevel_sb); | |
521 | ||
522 | // Background buffer size | |
523 | QSpinBox *buffersize_sb = new QSpinBox(); | |
524 | buffersize_sb->setSuffix(tr(" lines")); | |
525 | buffersize_sb->setMinimum(Logging::MIN_BUFFER_SIZE); | |
526 | buffersize_sb->setMaximum(Logging::MAX_BUFFER_SIZE); | |
527 | buffersize_sb->setValue( | |
528 | settings.value(GlobalSettings::Key_Log_BufferSize).toInt()); | |
529 | connect(buffersize_sb, SIGNAL(valueChanged(int)), this, | |
530 | SLOT(on_log_bufferSize_changed(int))); | |
531 | ||
532 | QHBoxLayout *buffersize_layout = new QHBoxLayout(); | |
533 | buffersize_layout->addWidget(new QLabel(tr("Length of background buffer:"))); | |
534 | buffersize_layout->addWidget(buffersize_sb); | |
535 | ||
536 | // Save to file | |
537 | QPushButton *save_log_pb = new QPushButton( | |
538 | QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")), | |
539 | tr("&Save to File")); | |
540 | connect(save_log_pb, SIGNAL(clicked(bool)), | |
541 | this, SLOT(on_log_saveToFile_clicked(bool))); | |
542 | ||
543 | // Pop out | |
544 | QPushButton *pop_out_pb = new QPushButton( | |
545 | QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")), | |
546 | tr("&Pop out")); | |
547 | connect(pop_out_pb, SIGNAL(clicked(bool)), | |
548 | this, SLOT(on_log_popOut_clicked(bool))); | |
549 | ||
550 | QHBoxLayout *control_layout = new QHBoxLayout(); | |
551 | control_layout->addLayout(loglevel_layout); | |
552 | control_layout->addLayout(buffersize_layout); | |
553 | control_layout->addWidget(save_log_pb); | |
554 | control_layout->addWidget(pop_out_pb); | |
555 | ||
556 | QVBoxLayout *root_layout = new QVBoxLayout(); | |
557 | root_layout->addLayout(control_layout); | |
558 | root_layout->addWidget(log_view_); | |
559 | ||
560 | QWidget *page = new QWidget(parent); | |
561 | page->setLayout(root_layout); | |
562 | ||
563 | return page; | |
564 | } | |
565 | ||
566 | void Settings::accept() | |
567 | { | |
568 | GlobalSettings settings; | |
569 | settings.stop_tracking(); | |
570 | ||
571 | QDialog::accept(); | |
572 | } | |
573 | ||
574 | void Settings::reject() | |
575 | { | |
576 | GlobalSettings settings; | |
577 | settings.undo_tracked_changes(); | |
578 | ||
579 | QDialog::reject(); | |
580 | } | |
581 | ||
582 | void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous) | |
583 | { | |
584 | if (!current) | |
585 | current = previous; | |
586 | ||
587 | pages->setCurrentIndex(page_list->row(current)); | |
588 | } | |
589 | ||
590 | void Settings::on_view_zoomToFitDuringAcq_changed(int state) | |
591 | { | |
592 | GlobalSettings settings; | |
593 | settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false); | |
594 | } | |
595 | ||
596 | void Settings::on_view_zoomToFitAfterAcq_changed(int state) | |
597 | { | |
598 | GlobalSettings settings; | |
599 | settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false); | |
600 | } | |
601 | ||
602 | void Settings::on_view_triggerIsZero_changed(int state) | |
603 | { | |
604 | GlobalSettings settings; | |
605 | settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false); | |
606 | } | |
607 | ||
608 | void Settings::on_view_coloredBG_changed(int state) | |
609 | { | |
610 | GlobalSettings settings; | |
611 | settings.setValue(GlobalSettings::Key_View_ColoredBG, state ? true : false); | |
612 | } | |
613 | ||
614 | void Settings::on_view_stickyScrolling_changed(int state) | |
615 | { | |
616 | GlobalSettings settings; | |
617 | settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false); | |
618 | } | |
619 | ||
620 | void Settings::on_view_showSamplingPoints_changed(int state) | |
621 | { | |
622 | GlobalSettings settings; | |
623 | settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false); | |
624 | } | |
625 | ||
626 | void Settings::on_view_showAnalogMinorGrid_changed(int state) | |
627 | { | |
628 | GlobalSettings settings; | |
629 | settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false); | |
630 | } | |
631 | ||
632 | void Settings::on_view_showHoverMarker_changed(int state) | |
633 | { | |
634 | GlobalSettings settings; | |
635 | settings.setValue(GlobalSettings::Key_View_ShowHoverMarker, state ? true : false); | |
636 | } | |
637 | ||
638 | void Settings::on_view_snapDistance_changed(int value) | |
639 | { | |
640 | GlobalSettings settings; | |
641 | settings.setValue(GlobalSettings::Key_View_SnapDistance, value); | |
642 | } | |
643 | ||
644 | void Settings::on_view_conversionThresholdDispMode_changed(int state) | |
645 | { | |
646 | GlobalSettings settings; | |
647 | settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state); | |
648 | } | |
649 | ||
650 | void Settings::on_view_defaultDivHeight_changed(int value) | |
651 | { | |
652 | GlobalSettings settings; | |
653 | settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value); | |
654 | } | |
655 | ||
656 | void Settings::on_view_defaultLogicHeight_changed(int value) | |
657 | { | |
658 | GlobalSettings settings; | |
659 | settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value); | |
660 | } | |
661 | ||
662 | #ifdef ENABLE_DECODE | |
663 | void Settings::on_dec_initialStateConfigurable_changed(int state) | |
664 | { | |
665 | GlobalSettings settings; | |
666 | settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false); | |
667 | } | |
668 | ||
669 | void Settings::on_dec_exportFormat_changed(const QString &text) | |
670 | { | |
671 | GlobalSettings settings; | |
672 | settings.setValue(GlobalSettings::Key_Dec_ExportFormat, text); | |
673 | } | |
674 | #endif | |
675 | ||
676 | void Settings::on_log_logLevel_changed(int value) | |
677 | { | |
678 | logging.set_log_level(value); | |
679 | } | |
680 | ||
681 | void Settings::on_log_bufferSize_changed(int value) | |
682 | { | |
683 | GlobalSettings settings; | |
684 | settings.setValue(GlobalSettings::Key_Log_BufferSize, value); | |
685 | } | |
686 | ||
687 | void Settings::on_log_saveToFile_clicked(bool checked) | |
688 | { | |
689 | (void)checked; | |
690 | ||
691 | const QString file_name = QFileDialog::getSaveFileName( | |
692 | this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)")); | |
693 | ||
694 | if (file_name.isEmpty()) | |
695 | return; | |
696 | ||
697 | QFile file(file_name); | |
698 | if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { | |
699 | QTextStream out_stream(&file); | |
700 | out_stream << log_view_->toPlainText(); | |
701 | ||
702 | if (out_stream.status() == QTextStream::Ok) { | |
703 | QMessageBox msg(this); | |
704 | msg.setText(tr("Success")); | |
705 | msg.setInformativeText(tr("Log saved to %1.").arg(file_name)); | |
706 | msg.setStandardButtons(QMessageBox::Ok); | |
707 | msg.setIcon(QMessageBox::Information); | |
708 | msg.exec(); | |
709 | ||
710 | return; | |
711 | } | |
712 | } | |
713 | ||
714 | QMessageBox msg(this); | |
715 | msg.setText(tr("Error")); | |
716 | msg.setInformativeText(tr("File %1 could not be written to.").arg(file_name)); | |
717 | msg.setStandardButtons(QMessageBox::Ok); | |
718 | msg.setIcon(QMessageBox::Warning); | |
719 | msg.exec(); | |
720 | } | |
721 | ||
722 | void Settings::on_log_popOut_clicked(bool checked) | |
723 | { | |
724 | (void)checked; | |
725 | ||
726 | // Create the window as a sub-window so it closes when the main window closes | |
727 | QMainWindow *window = new QMainWindow(nullptr, Qt::SubWindow); | |
728 | ||
729 | window->setObjectName(QString::fromUtf8("Log Window")); | |
730 | window->setWindowTitle(tr("%1 Log").arg(PV_TITLE)); | |
731 | ||
732 | // Use same width/height as the settings dialog | |
733 | window->resize(width(), height()); | |
734 | ||
735 | window->setCentralWidget(create_log_view()); | |
736 | window->show(); | |
737 | } | |
738 | ||
739 | } // namespace dialogs | |
740 | } // namespace pv |