Properly handle decoder errors
[pulseview.git] / pv / dialogs / settings.cpp
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         QComboBox *thr_disp_mode_cb = new QComboBox();
241         thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
242         thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
243         thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots);
244         thr_disp_mode_cb->setCurrentIndex(
245                 settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt());
246         connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)),
247                 this, SLOT(on_view_conversionThresholdDispMode_changed(int)));
248         trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb);
249
250         QSpinBox *default_div_height_sb = new QSpinBox();
251         default_div_height_sb->setRange(20, 1000);
252         default_div_height_sb->setSuffix(tr(" pixels"));
253         default_div_height_sb->setValue(
254                 settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt());
255         connect(default_div_height_sb, SIGNAL(valueChanged(int)), this,
256                 SLOT(on_view_defaultDivHeight_changed(int)));
257         trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb);
258
259         QSpinBox *default_logic_height_sb = new QSpinBox();
260         default_logic_height_sb->setRange(5, 1000);
261         default_logic_height_sb->setSuffix(tr(" pixels"));
262         default_logic_height_sb->setValue(
263                 settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt());
264         connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this,
265                 SLOT(on_view_defaultLogicHeight_changed(int)));
266         trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb);
267
268         return form;
269 }
270
271 QWidget *Settings::get_decoder_settings_form(QWidget *parent) const
272 {
273 #ifdef ENABLE_DECODE
274         QCheckBox *cb;
275
276         QWidget *form = new QWidget(parent);
277         QVBoxLayout *form_layout = new QVBoxLayout(form);
278
279         // Decoder settings
280         QGroupBox *decoder_group = new QGroupBox(tr("Decoders"));
281         form_layout->addWidget(decoder_group);
282
283         QFormLayout *decoder_layout = new QFormLayout();
284         decoder_group->setLayout(decoder_layout);
285
286         cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable,
287                 SLOT(on_dec_initialStateConfigurable_changed(int)));
288         decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb);
289
290         return form;
291 #else
292         (void)parent;
293         return nullptr;
294 #endif
295 }
296
297 #ifdef ENABLE_DECODE
298 static gint sort_pds(gconstpointer a, gconstpointer b)
299 {
300         const struct srd_decoder *sda, *sdb;
301
302         sda = (const struct srd_decoder *)a;
303         sdb = (const struct srd_decoder *)b;
304         return strcmp(sda->id, sdb->id);
305 }
306 #endif
307
308 QWidget *Settings::get_about_page(QWidget *parent) const
309 {
310 #ifdef ENABLE_DECODE
311         struct srd_decoder *dec;
312 #endif
313
314         QLabel *icon = new QLabel();
315         icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg")));
316
317         /* Setup the version field */
318         QLabel *version_info = new QLabel();
319         version_info->setText(tr("%1 %2<br />%3<br /><a href=\"http://%4\">%4</a>")
320                 .arg(QApplication::applicationName(),
321                 QApplication::applicationVersion(),
322                 tr("GNU GPL, version 3 or later"),
323                 QApplication::organizationDomain()));
324         version_info->setOpenExternalLinks(true);
325
326         shared_ptr<sigrok::Context> context = device_manager_.context();
327
328         QString s;
329
330         s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
331
332         s.append("<table>");
333
334         /* Library info */
335         s.append("<tr><td colspan=\"2\"><b>" +
336                 tr("Libraries and features:") + "</b></td></tr>");
337
338         s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
339                 .arg(QString("Qt"), qVersion()));
340         s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
341                 .arg(QString("glibmm"), PV_GLIBMM_VERSION));
342         s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
343                 .arg(QString("Boost"), BOOST_LIB_VERSION));
344
345         s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
346                 .arg(QString("libsigrok"), SR_PACKAGE_VERSION_STRING,
347                 SR_LIB_VERSION_STRING, sr_package_version_string_get(),
348                 sr_lib_version_string_get()));
349
350         GSList *l_orig = sr_buildinfo_libs_get();
351         for (GSList *l = l_orig; l; l = l->next) {
352                 GSList *m = (GSList *)l->data;
353                 const char *lib = (const char *)m->data;
354                 const char *version = (const char *)m->next->data;
355                 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
356                         .arg(QString(lib), QString(version)));
357                 g_slist_free_full(m, g_free);
358         }
359         g_slist_free(l_orig);
360
361         char *host = sr_buildinfo_host_get();
362         s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
363                 .arg(QString(host)));
364         g_free(host);
365
366         char *scpi_backends = sr_buildinfo_scpi_backends_get();
367         s.append(QString("<tr><td><i>- SCPI backends</i></td><td>%1</td></tr>")
368                 .arg(QString(scpi_backends)));
369         g_free(scpi_backends);
370
371 #ifdef ENABLE_DECODE
372         s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
373                 .arg(QString("libsigrokdecode"), SRD_PACKAGE_VERSION_STRING,
374                 SRD_LIB_VERSION_STRING, srd_package_version_string_get(),
375                 srd_lib_version_string_get()));
376
377         l_orig = srd_buildinfo_libs_get();
378         for (GSList *l = l_orig; l; l = l->next) {
379                 GSList *m = (GSList *)l->data;
380                 const char *lib = (const char *)m->data;
381                 const char *version = (const char *)m->next->data;
382                 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
383                         .arg(QString(lib), QString(version)));
384                 g_slist_free_full(m, g_free);
385         }
386         g_slist_free(l_orig);
387
388         host = srd_buildinfo_host_get();
389         s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
390                 .arg(QString(host)));
391         g_free(host);
392 #endif
393
394         s.append("<tr><td colspan=\"2\"></td></tr>");
395         s.append("<tr><td colspan=\"2\"><b>" +
396                 tr("Firmware search paths:") + "</b></td></tr>");
397
398         l_orig = sr_resourcepaths_get(SR_RESOURCE_FIRMWARE);
399         for (GSList *l = l_orig; l; l = l->next)
400                 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(
401                         QString((char*)l->data)));
402         g_slist_free_full(l_orig, g_free);
403
404 #ifdef ENABLE_DECODE
405         s.append("<tr><td colspan=\"2\"></td></tr>");
406         s.append("<tr><td colspan=\"2\"><b>" +
407                 tr("Protocol decoder search paths:") + "</b></td></tr>");
408
409         l_orig = srd_searchpaths_get();
410         for (GSList *l = l_orig; l; l = l->next)
411                 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(
412                         QString((char*)l->data)));
413         g_slist_free_full(l_orig, g_free);
414 #endif
415
416         /* Set up the supported field */
417         s.append("<tr><td colspan=\"2\"></td></tr>");
418         s.append("<tr><td colspan=\"2\"><b>" +
419                 tr("Supported hardware drivers:") + "</b></td></tr>");
420         for (auto entry : context->drivers()) {
421                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
422                         .arg(QString::fromUtf8(entry.first.c_str()),
423                                 QString::fromUtf8(entry.second->long_name().c_str())));
424         }
425
426         s.append("<tr><td colspan=\"2\"></td></tr>");
427         s.append("<tr><td colspan=\"2\"><b>" +
428                 tr("Supported input formats:") + "</b></td></tr>");
429         for (auto entry : context->input_formats()) {
430                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
431                         .arg(QString::fromUtf8(entry.first.c_str()),
432                                 QString::fromUtf8(entry.second->description().c_str())));
433         }
434
435         s.append("<tr><td colspan=\"2\"></td></tr>");
436         s.append("<tr><td colspan=\"2\"><b>" +
437                 tr("Supported output formats:") + "</b></td></tr>");
438         for (auto entry : context->output_formats()) {
439                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
440                         .arg(QString::fromUtf8(entry.first.c_str()),
441                                 QString::fromUtf8(entry.second->description().c_str())));
442         }
443
444 #ifdef ENABLE_DECODE
445         s.append("<tr><td colspan=\"2\"></td></tr>");
446         s.append("<tr><td colspan=\"2\"><b>" +
447                 tr("Supported protocol decoders:") + "</b></td></tr>");
448         GSList *sl = g_slist_copy((GSList *)srd_decoder_list());
449         sl = g_slist_sort(sl, sort_pds);
450         for (const GSList *l = sl; l; l = l->next) {
451                 dec = (struct srd_decoder *)l->data;
452                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
453                         .arg(QString::fromUtf8(dec->id),
454                                 QString::fromUtf8(dec->longname)));
455         }
456         g_slist_free(sl);
457 #endif
458
459         s.append("</table>");
460
461         QTextDocument *supported_doc = new QTextDocument();
462         supported_doc->setHtml(s);
463
464         QTextBrowser *support_list = new QTextBrowser();
465         support_list->setDocument(supported_doc);
466
467         QGridLayout *layout = new QGridLayout();
468         layout->addWidget(icon, 0, 0, 1, 1);
469         layout->addWidget(version_info, 0, 1, 1, 1);
470         layout->addWidget(support_list, 1, 1, 1, 1);
471
472         QWidget *page = new QWidget(parent);
473         page->setLayout(layout);
474
475         return page;
476 }
477
478 QWidget *Settings::get_logging_page(QWidget *parent) const
479 {
480         GlobalSettings settings;
481
482         // Log level
483         QSpinBox *loglevel_sb = new QSpinBox();
484         loglevel_sb->setMaximum(SR_LOG_SPEW);
485         loglevel_sb->setValue(logging.get_log_level());
486         connect(loglevel_sb, SIGNAL(valueChanged(int)), this,
487                 SLOT(on_log_logLevel_changed(int)));
488
489         QHBoxLayout *loglevel_layout = new QHBoxLayout();
490         loglevel_layout->addWidget(new QLabel(tr("Log level:")));
491         loglevel_layout->addWidget(loglevel_sb);
492
493         // Background buffer size
494         QSpinBox *buffersize_sb = new QSpinBox();
495         buffersize_sb->setSuffix(tr(" lines"));
496         buffersize_sb->setMinimum(Logging::MIN_BUFFER_SIZE);
497         buffersize_sb->setMaximum(Logging::MAX_BUFFER_SIZE);
498         buffersize_sb->setValue(
499                 settings.value(GlobalSettings::Key_Log_BufferSize).toInt());
500         connect(buffersize_sb, SIGNAL(valueChanged(int)), this,
501                 SLOT(on_log_bufferSize_changed(int)));
502
503         QHBoxLayout *buffersize_layout = new QHBoxLayout();
504         buffersize_layout->addWidget(new QLabel(tr("Length of background buffer:")));
505         buffersize_layout->addWidget(buffersize_sb);
506
507         // Save to file
508         QPushButton *save_log_pb = new QPushButton(
509                 QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")),
510                 tr("&Save to File"));
511         connect(save_log_pb, SIGNAL(clicked(bool)),
512                 this, SLOT(on_log_saveToFile_clicked(bool)));
513
514         // Pop out
515         QPushButton *pop_out_pb = new QPushButton(
516                 QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")),
517                 tr("&Pop out"));
518         connect(pop_out_pb, SIGNAL(clicked(bool)),
519                 this, SLOT(on_log_popOut_clicked(bool)));
520
521         QHBoxLayout *control_layout = new QHBoxLayout();
522         control_layout->addLayout(loglevel_layout);
523         control_layout->addLayout(buffersize_layout);
524         control_layout->addWidget(save_log_pb);
525         control_layout->addWidget(pop_out_pb);
526
527         QVBoxLayout *root_layout = new QVBoxLayout();
528         root_layout->addLayout(control_layout);
529         root_layout->addWidget(log_view_);
530
531         QWidget *page = new QWidget(parent);
532         page->setLayout(root_layout);
533
534         return page;
535 }
536
537 void Settings::accept()
538 {
539         GlobalSettings settings;
540         settings.stop_tracking();
541
542         QDialog::accept();
543 }
544
545 void Settings::reject()
546 {
547         GlobalSettings settings;
548         settings.undo_tracked_changes();
549
550         QDialog::reject();
551 }
552
553 void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
554 {
555         if (!current)
556                 current = previous;
557
558         pages->setCurrentIndex(page_list->row(current));
559 }
560
561 void Settings::on_view_zoomToFitDuringAcq_changed(int state)
562 {
563         GlobalSettings settings;
564         settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false);
565 }
566
567 void Settings::on_view_zoomToFitAfterAcq_changed(int state)
568 {
569         GlobalSettings settings;
570         settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false);
571 }
572
573 void Settings::on_view_triggerIsZero_changed(int state)
574 {
575         GlobalSettings settings;
576         settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false);
577 }
578
579 void Settings::on_view_coloredBG_changed(int state)
580 {
581         GlobalSettings settings;
582         settings.setValue(GlobalSettings::Key_View_ColoredBG, state ? true : false);
583 }
584
585 void Settings::on_view_stickyScrolling_changed(int state)
586 {
587         GlobalSettings settings;
588         settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
589 }
590
591 void Settings::on_view_showSamplingPoints_changed(int state)
592 {
593         GlobalSettings settings;
594         settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
595 }
596
597 void Settings::on_view_showAnalogMinorGrid_changed(int state)
598 {
599         GlobalSettings settings;
600         settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
601 }
602
603 void Settings::on_view_showHoverMarker_changed(int state)
604 {
605         GlobalSettings settings;
606         settings.setValue(GlobalSettings::Key_View_ShowHoverMarker, state ? true : false);
607 }
608
609 void Settings::on_view_conversionThresholdDispMode_changed(int state)
610 {
611         GlobalSettings settings;
612         settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state);
613 }
614
615 void Settings::on_view_defaultDivHeight_changed(int value)
616 {
617         GlobalSettings settings;
618         settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value);
619 }
620
621 void Settings::on_view_defaultLogicHeight_changed(int value)
622 {
623         GlobalSettings settings;
624         settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value);
625 }
626
627 void Settings::on_dec_initialStateConfigurable_changed(int state)
628 {
629         GlobalSettings settings;
630         settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false);
631 }
632
633 void Settings::on_log_logLevel_changed(int value)
634 {
635         logging.set_log_level(value);
636 }
637
638 void Settings::on_log_bufferSize_changed(int value)
639 {
640         GlobalSettings settings;
641         settings.setValue(GlobalSettings::Key_Log_BufferSize, value);
642 }
643
644 void Settings::on_log_saveToFile_clicked(bool checked)
645 {
646         (void)checked;
647
648         const QString file_name = QFileDialog::getSaveFileName(
649                 this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)"));
650
651         if (file_name.isEmpty())
652                 return;
653
654         QFile file(file_name);
655         if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
656                 QTextStream out_stream(&file);
657                 out_stream << log_view_->toPlainText();
658
659                 if (out_stream.status() == QTextStream::Ok) {
660                         QMessageBox msg(this);
661                         msg.setText(tr("Success"));
662                         msg.setInformativeText(tr("Log saved to %1.").arg(file_name));
663                         msg.setStandardButtons(QMessageBox::Ok);
664                         msg.setIcon(QMessageBox::Information);
665                         msg.exec();
666
667                         return;
668                 }
669         }
670
671         QMessageBox msg(this);
672         msg.setText(tr("Error"));
673         msg.setInformativeText(tr("File %1 could not be written to.").arg(file_name));
674         msg.setStandardButtons(QMessageBox::Ok);
675         msg.setIcon(QMessageBox::Warning);
676         msg.exec();
677 }
678
679 void Settings::on_log_popOut_clicked(bool checked)
680 {
681         (void)checked;
682
683         // Create the window as a sub-window so it closes when the main window closes
684         QMainWindow *window = new QMainWindow(nullptr, Qt::SubWindow);
685
686         window->setObjectName(QString::fromUtf8("Log Window"));
687         window->setWindowTitle(tr("%1 Log").arg(PV_TITLE));
688
689         // Use same width/height as the settings dialog
690         window->resize(width(), height());
691
692         window->setCentralWidget(create_log_view());
693         window->show();
694 }
695
696 } // namespace dialogs
697 } // namespace pv