Main: Create human-readable stack trace and notify user
[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 <QSpinBox>
37 #include <QString>
38 #include <QTextBrowser>
39 #include <QTextDocument>
40 #include <QTextStream>
41 #include <QVBoxLayout>
42
43 #include "settings.hpp"
44
45 #include "pv/devicemanager.hpp"
46 #include "pv/globalsettings.hpp"
47 #include "pv/logging.hpp"
48
49 #include <libsigrokcxx/libsigrokcxx.hpp>
50
51 #ifdef ENABLE_DECODE
52 #include <libsigrokdecode/libsigrokdecode.h>
53 #endif
54
55 using std::shared_ptr;
56
57 namespace pv {
58 namespace dialogs {
59
60 Settings::Settings(DeviceManager &device_manager, QWidget *parent) :
61         QDialog(parent, nullptr),
62         device_manager_(device_manager)
63 {
64         const int icon_size = 64;
65
66         resize(600, 400);
67
68         // Create log view
69         log_view_ = create_log_view();
70
71         // Create pages
72         page_list = new QListWidget;
73         page_list->setViewMode(QListView::IconMode);
74         page_list->setIconSize(QSize(icon_size, icon_size));
75         page_list->setMovement(QListView::Static);
76         page_list->setMaximumWidth(icon_size + (icon_size / 2));
77         page_list->setSpacing(12);
78
79         pages = new QStackedWidget;
80         create_pages();
81         page_list->setCurrentIndex(page_list->model()->index(0, 0));
82
83         QHBoxLayout *tab_layout = new QHBoxLayout;
84         tab_layout->addWidget(page_list);
85         tab_layout->addWidget(pages, Qt::AlignLeft);
86
87         QDialogButtonBox *button_box = new QDialogButtonBox(
88                 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
89
90         QVBoxLayout* root_layout = new QVBoxLayout(this);
91         root_layout->addLayout(tab_layout);
92         root_layout->addWidget(button_box);
93
94         connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
95         connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
96         connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
97                 this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*)));
98
99         // Start to record changes
100         GlobalSettings settings;
101         settings.start_tracking();
102 }
103
104 void Settings::create_pages()
105 {
106         // View page
107         pages->addWidget(get_view_settings_form(pages));
108
109         QListWidgetItem *viewButton = new QListWidgetItem(page_list);
110         viewButton->setIcon(QIcon(":/icons/settings-views.svg"));
111         viewButton->setText(tr("Views"));
112         viewButton->setTextAlignment(Qt::AlignHCenter);
113         viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
114
115 #ifdef ENABLE_DECODE
116         // Decoder page
117         pages->addWidget(get_decoder_settings_form(pages));
118
119         QListWidgetItem *decoderButton = new QListWidgetItem(page_list);
120         decoderButton->setIcon(QIcon(":/icons/add-decoder.svg"));
121         decoderButton->setText(tr("Decoders"));
122         decoderButton->setTextAlignment(Qt::AlignHCenter);
123         decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
124 #endif
125
126         // About page
127         pages->addWidget(get_about_page(pages));
128
129         QListWidgetItem *aboutButton = new QListWidgetItem(page_list);
130         aboutButton->setIcon(QIcon(":/icons/information.svg"));
131         aboutButton->setText(tr("About"));
132         aboutButton->setTextAlignment(Qt::AlignHCenter);
133         aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
134
135         // Logging page
136         pages->addWidget(get_logging_page(pages));
137
138         QListWidgetItem *loggingButton = new QListWidgetItem(page_list);
139         loggingButton->setIcon(QIcon(":/icons/information.svg"));
140         loggingButton->setText(tr("Logging"));
141         loggingButton->setTextAlignment(Qt::AlignHCenter);
142         loggingButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
143 }
144
145 QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const
146 {
147         GlobalSettings settings;
148
149         QCheckBox *cb = new QCheckBox();
150         cb->setChecked(settings.value(key).toBool());
151         connect(cb, SIGNAL(stateChanged(int)), this, slot);
152         return cb;
153 }
154
155 QPlainTextEdit *Settings::create_log_view() const
156 {
157         GlobalSettings settings;
158
159         QPlainTextEdit *log_view = new QPlainTextEdit();
160
161         log_view->setReadOnly(true);
162         log_view->setWordWrapMode(QTextOption::NoWrap);
163         log_view->setCenterOnScroll(true);
164
165         log_view->appendHtml(logging.get_log());
166         connect(&logging, SIGNAL(logged_text(QString)),
167                 log_view, SLOT(appendHtml(QString)));
168
169         return log_view;
170 }
171
172 QWidget *Settings::get_view_settings_form(QWidget *parent) const
173 {
174         GlobalSettings settings;
175         QCheckBox *cb;
176
177         QWidget *form = new QWidget(parent);
178         QVBoxLayout *form_layout = new QVBoxLayout(form);
179
180         // Trace view settings
181         QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
182         form_layout->addWidget(trace_view_group);
183
184         QFormLayout *trace_view_layout = new QFormLayout();
185         trace_view_group->setLayout(trace_view_layout);
186
187         cb = create_checkbox(GlobalSettings::Key_View_ColouredBG,
188                 SLOT(on_view_colouredBG_changed(int)));
189         trace_view_layout->addRow(tr("Use coloured trace &background"), cb);
190
191         cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq,
192                 SLOT(on_view_zoomToFitDuringAcq_changed(int)));
193         trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb);
194
195         cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq,
196                 SLOT(on_view_zoomToFitAfterAcq_changed(int)));
197         trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb);
198
199         cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime,
200                 SLOT(on_view_triggerIsZero_changed(int)));
201         trace_view_layout->addRow(tr("Show time zero at the trigger"), cb);
202
203         cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling,
204                 SLOT(on_view_stickyScrolling_changed(int)));
205         trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb);
206
207         cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints,
208                 SLOT(on_view_showSamplingPoints_changed(int)));
209         trace_view_layout->addRow(tr("Show data &sampling points"), cb);
210
211         cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid,
212                 SLOT(on_view_showAnalogMinorGrid_changed(int)));
213         trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb);
214
215         QComboBox *thr_disp_mode_cb = new QComboBox();
216         thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
217         thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
218         thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots);
219         thr_disp_mode_cb->setCurrentIndex(
220                 settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt());
221         connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)),
222                 this, SLOT(on_view_conversionThresholdDispMode_changed(int)));
223         trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb);
224
225         QSpinBox *default_div_height_sb = new QSpinBox();
226         default_div_height_sb->setRange(20, 1000);
227         default_div_height_sb->setSuffix(tr(" pixels"));
228         default_div_height_sb->setValue(
229                 settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt());
230         connect(default_div_height_sb, SIGNAL(valueChanged(int)), this,
231                 SLOT(on_view_defaultDivHeight_changed(int)));
232         trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb);
233
234         QSpinBox *default_logic_height_sb = new QSpinBox();
235         default_logic_height_sb->setRange(5, 1000);
236         default_logic_height_sb->setSuffix(tr(" pixels"));
237         default_logic_height_sb->setValue(
238                 settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt());
239         connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this,
240                 SLOT(on_view_defaultLogicHeight_changed(int)));
241         trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb);
242
243         return form;
244 }
245
246 QWidget *Settings::get_decoder_settings_form(QWidget *parent) const
247 {
248 #ifdef ENABLE_DECODE
249         QCheckBox *cb;
250
251         QWidget *form = new QWidget(parent);
252         QVBoxLayout *form_layout = new QVBoxLayout(form);
253
254         // Decoder settings
255         QGroupBox *decoder_group = new QGroupBox(tr("Decoders"));
256         form_layout->addWidget(decoder_group);
257
258         QFormLayout *decoder_layout = new QFormLayout();
259         decoder_group->setLayout(decoder_layout);
260
261         cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable,
262                 SLOT(on_dec_initialStateConfigurable_changed(int)));
263         decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb);
264
265         return form;
266 #else
267         (void)parent;
268         return nullptr;
269 #endif
270 }
271
272 #ifdef ENABLE_DECODE
273 static gint sort_pds(gconstpointer a, gconstpointer b)
274 {
275         const struct srd_decoder *sda, *sdb;
276
277         sda = (const struct srd_decoder *)a;
278         sdb = (const struct srd_decoder *)b;
279         return strcmp(sda->id, sdb->id);
280 }
281 #endif
282
283 QWidget *Settings::get_about_page(QWidget *parent) const
284 {
285 #ifdef ENABLE_DECODE
286         struct srd_decoder *dec;
287 #endif
288
289         QLabel *icon = new QLabel();
290         icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg")));
291
292         /* Setup the version field */
293         QLabel *version_info = new QLabel();
294         version_info->setText(tr("%1 %2<br />%3<br /><a href=\"http://%4\">%4</a>")
295                 .arg(QApplication::applicationName(),
296                 QApplication::applicationVersion(),
297                 tr("GNU GPL, version 3 or later"),
298                 QApplication::organizationDomain()));
299         version_info->setOpenExternalLinks(true);
300
301         shared_ptr<sigrok::Context> context = device_manager_.context();
302
303         QString s;
304
305         s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
306
307         s.append("<table>");
308
309         /* Library info */
310         s.append("<tr><td colspan=\"2\"><b>" +
311                 tr("Libraries and features:") + "</b></td></tr>");
312
313         s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
314                 .arg(QString("Qt"), qVersion()));
315         s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
316                 .arg(QString("glibmm"), PV_GLIBMM_VERSION));
317         s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
318                 .arg(QString("Boost"), BOOST_LIB_VERSION));
319
320         s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
321                 .arg(QString("libsigrok"), SR_PACKAGE_VERSION_STRING,
322                 SR_LIB_VERSION_STRING, sr_package_version_string_get(),
323                 sr_lib_version_string_get()));
324
325         GSList *l_orig = sr_buildinfo_libs_get();
326         for (GSList *l = l_orig; l; l = l->next) {
327                 GSList *m = (GSList *)l->data;
328                 const char *lib = (const char *)m->data;
329                 const char *version = (const char *)m->next->data;
330                 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
331                         .arg(QString(lib), QString(version)));
332                 g_slist_free_full(m, g_free);
333         }
334         g_slist_free(l_orig);
335
336         char *host = sr_buildinfo_host_get();
337         s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
338                 .arg(QString(host)));
339         g_free(host);
340
341         char *scpi_backends = sr_buildinfo_scpi_backends_get();
342         s.append(QString("<tr><td><i>- SCPI backends</i></td><td>%1</td></tr>")
343                 .arg(QString(scpi_backends)));
344         g_free(scpi_backends);
345
346 #ifdef ENABLE_DECODE
347         s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
348                 .arg(QString("libsigrokdecode"), SRD_PACKAGE_VERSION_STRING,
349                 SRD_LIB_VERSION_STRING, srd_package_version_string_get(),
350                 srd_lib_version_string_get()));
351
352         l_orig = srd_buildinfo_libs_get();
353         for (GSList *l = l_orig; l; l = l->next) {
354                 GSList *m = (GSList *)l->data;
355                 const char *lib = (const char *)m->data;
356                 const char *version = (const char *)m->next->data;
357                 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
358                         .arg(QString(lib), QString(version)));
359                 g_slist_free_full(m, g_free);
360         }
361         g_slist_free(l_orig);
362
363         host = srd_buildinfo_host_get();
364         s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
365                 .arg(QString(host)));
366         g_free(host);
367 #endif
368
369         s.append("<tr><td colspan=\"2\"></td></tr>");
370         s.append("<tr><td colspan=\"2\"><b>" +
371                 tr("Firmware search paths:") + "</b></td></tr>");
372
373         l_orig = sr_resourcepaths_get(SR_RESOURCE_FIRMWARE);
374         for (GSList *l = l_orig; l; l = l->next)
375                 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(
376                         QString((char*)l->data)));
377         g_slist_free_full(l_orig, g_free);
378
379 #ifdef ENABLE_DECODE
380         s.append("<tr><td colspan=\"2\"></td></tr>");
381         s.append("<tr><td colspan=\"2\"><b>" +
382                 tr("Protocol decoder search paths:") + "</b></td></tr>");
383
384         l_orig = srd_searchpaths_get();
385         for (GSList *l = l_orig; l; l = l->next)
386                 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(
387                         QString((char*)l->data)));
388         g_slist_free_full(l_orig, g_free);
389 #endif
390
391         /* Set up the supported field */
392         s.append("<tr><td colspan=\"2\"></td></tr>");
393         s.append("<tr><td colspan=\"2\"><b>" +
394                 tr("Supported hardware drivers:") + "</b></td></tr>");
395         for (auto entry : context->drivers()) {
396                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
397                         .arg(QString::fromUtf8(entry.first.c_str()),
398                                 QString::fromUtf8(entry.second->long_name().c_str())));
399         }
400
401         s.append("<tr><td colspan=\"2\"></td></tr>");
402         s.append("<tr><td colspan=\"2\"><b>" +
403                 tr("Supported input formats:") + "</b></td></tr>");
404         for (auto entry : context->input_formats()) {
405                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
406                         .arg(QString::fromUtf8(entry.first.c_str()),
407                                 QString::fromUtf8(entry.second->description().c_str())));
408         }
409
410         s.append("<tr><td colspan=\"2\"></td></tr>");
411         s.append("<tr><td colspan=\"2\"><b>" +
412                 tr("Supported output formats:") + "</b></td></tr>");
413         for (auto entry : context->output_formats()) {
414                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
415                         .arg(QString::fromUtf8(entry.first.c_str()),
416                                 QString::fromUtf8(entry.second->description().c_str())));
417         }
418
419 #ifdef ENABLE_DECODE
420         s.append("<tr><td colspan=\"2\"></td></tr>");
421         s.append("<tr><td colspan=\"2\"><b>" +
422                 tr("Supported protocol decoders:") + "</b></td></tr>");
423         GSList *sl = g_slist_copy((GSList *)srd_decoder_list());
424         sl = g_slist_sort(sl, sort_pds);
425         for (const GSList *l = sl; l; l = l->next) {
426                 dec = (struct srd_decoder *)l->data;
427                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
428                         .arg(QString::fromUtf8(dec->id),
429                                 QString::fromUtf8(dec->longname)));
430         }
431         g_slist_free(sl);
432 #endif
433
434         s.append("</table>");
435
436         QTextDocument *supported_doc = new QTextDocument();
437         supported_doc->setHtml(s);
438
439         QTextBrowser *support_list = new QTextBrowser();
440         support_list->setDocument(supported_doc);
441
442         QGridLayout *layout = new QGridLayout();
443         layout->addWidget(icon, 0, 0, 1, 1);
444         layout->addWidget(version_info, 0, 1, 1, 1);
445         layout->addWidget(support_list, 1, 1, 1, 1);
446
447         QWidget *page = new QWidget(parent);
448         page->setLayout(layout);
449
450         return page;
451 }
452
453 QWidget *Settings::get_logging_page(QWidget *parent) const
454 {
455         GlobalSettings settings;
456
457         // Log level
458         QSpinBox *loglevel_sb = new QSpinBox();
459         loglevel_sb->setMaximum(SR_LOG_SPEW);
460         loglevel_sb->setValue(logging.get_log_level());
461         connect(loglevel_sb, SIGNAL(valueChanged(int)), this,
462                 SLOT(on_log_logLevel_changed(int)));
463
464         QHBoxLayout *loglevel_layout = new QHBoxLayout();
465         loglevel_layout->addWidget(new QLabel(tr("Log level:")));
466         loglevel_layout->addWidget(loglevel_sb);
467
468         // Background buffer size
469         QSpinBox *buffersize_sb = new QSpinBox();
470         buffersize_sb->setSuffix(tr(" lines"));
471         buffersize_sb->setMaximum(Logging::MAX_BUFFER_SIZE);
472         buffersize_sb->setValue(
473                 settings.value(GlobalSettings::Key_Log_BufferSize).toInt());
474         connect(buffersize_sb, SIGNAL(valueChanged(int)), this,
475                 SLOT(on_log_bufferSize_changed(int)));
476
477         QHBoxLayout *buffersize_layout = new QHBoxLayout();
478         buffersize_layout->addWidget(new QLabel(tr("Length of background buffer:")));
479         buffersize_layout->addWidget(buffersize_sb);
480
481         // Save to file
482         QPushButton *save_log_pb = new QPushButton(
483                 QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")),
484                 tr("&Save to File"));
485         connect(save_log_pb, SIGNAL(clicked(bool)),
486                 this, SLOT(on_log_saveToFile_clicked(bool)));
487
488         // Pop out
489         QPushButton *pop_out_pb = new QPushButton(
490                 QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")),
491                 tr("&Pop out"));
492         connect(pop_out_pb, SIGNAL(clicked(bool)),
493                 this, SLOT(on_log_popOut_clicked(bool)));
494
495         QHBoxLayout *control_layout = new QHBoxLayout();
496         control_layout->addLayout(loglevel_layout);
497         control_layout->addLayout(buffersize_layout);
498         control_layout->addWidget(save_log_pb);
499         control_layout->addWidget(pop_out_pb);
500
501         QVBoxLayout *root_layout = new QVBoxLayout();
502         root_layout->addLayout(control_layout);
503         root_layout->addWidget(log_view_);
504
505         QWidget *page = new QWidget(parent);
506         page->setLayout(root_layout);
507
508         return page;
509 }
510
511 void Settings::accept()
512 {
513         GlobalSettings settings;
514         settings.stop_tracking();
515
516         QDialog::accept();
517 }
518
519 void Settings::reject()
520 {
521         GlobalSettings settings;
522         settings.undo_tracked_changes();
523
524         QDialog::reject();
525 }
526
527 void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
528 {
529         if (!current)
530                 current = previous;
531
532         pages->setCurrentIndex(page_list->row(current));
533 }
534
535 void Settings::on_view_zoomToFitDuringAcq_changed(int state)
536 {
537         GlobalSettings settings;
538         settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false);
539 }
540
541 void Settings::on_view_zoomToFitAfterAcq_changed(int state)
542 {
543         GlobalSettings settings;
544         settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false);
545 }
546
547 void Settings::on_view_triggerIsZero_changed(int state)
548 {
549         GlobalSettings settings;
550         settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false);
551 }
552
553 void Settings::on_view_colouredBG_changed(int state)
554 {
555         GlobalSettings settings;
556         settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
557 }
558
559 void Settings::on_view_stickyScrolling_changed(int state)
560 {
561         GlobalSettings settings;
562         settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
563 }
564
565 void Settings::on_view_showSamplingPoints_changed(int state)
566 {
567         GlobalSettings settings;
568         settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
569 }
570
571 void Settings::on_view_showAnalogMinorGrid_changed(int state)
572 {
573         GlobalSettings settings;
574         settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
575 }
576
577 void Settings::on_view_conversionThresholdDispMode_changed(int state)
578 {
579         GlobalSettings settings;
580         settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state);
581 }
582
583 void Settings::on_view_defaultDivHeight_changed(int value)
584 {
585         GlobalSettings settings;
586         settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value);
587 }
588
589 void Settings::on_view_defaultLogicHeight_changed(int value)
590 {
591         GlobalSettings settings;
592         settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value);
593 }
594
595 void Settings::on_dec_initialStateConfigurable_changed(int state)
596 {
597         GlobalSettings settings;
598         settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false);
599 }
600
601 void Settings::on_log_logLevel_changed(int value)
602 {
603         logging.set_log_level(value);
604 }
605
606 void Settings::on_log_bufferSize_changed(int value)
607 {
608         GlobalSettings settings;
609         settings.setValue(GlobalSettings::Key_Log_BufferSize, value);
610 }
611
612 void Settings::on_log_saveToFile_clicked(bool checked)
613 {
614         (void)checked;
615
616         const QString file_name = QFileDialog::getSaveFileName(
617                 this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)"));
618
619         if (file_name.isEmpty())
620                 return;
621
622         QFile file(file_name);
623         if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
624                 QTextStream out_stream(&file);
625                 out_stream << log_view_->toPlainText();
626
627                 if (out_stream.status() == QTextStream::Ok) {
628                         QMessageBox msg(this);
629                         msg.setText(tr("Success"));
630                         msg.setInformativeText(tr("Log saved to %1.").arg(file_name));
631                         msg.setStandardButtons(QMessageBox::Ok);
632                         msg.setIcon(QMessageBox::Information);
633                         msg.exec();
634
635                         return;
636                 }
637         }
638
639         QMessageBox msg(this);
640         msg.setText(tr("Error"));
641         msg.setInformativeText(tr("File %1 could not be written to.").arg(file_name));
642         msg.setStandardButtons(QMessageBox::Ok);
643         msg.setIcon(QMessageBox::Warning);
644         msg.exec();
645 }
646
647 void Settings::on_log_popOut_clicked(bool checked)
648 {
649         (void)checked;
650
651         // Create the window as a sub-window so it closes when the main window closes
652         QMainWindow *window = new QMainWindow(0, Qt::SubWindow);
653
654         window->setObjectName(QString::fromUtf8("Log Window"));
655         window->setWindowTitle(tr("%1 Log").arg(PV_TITLE));
656
657         // Use same width/height as the settings dialog
658         window->resize(width(), height());
659
660         window->setCentralWidget(create_log_view());
661         window->show();
662 }
663
664 } // namespace dialogs
665 } // namespace pv