]> sigrok.org Git - pulseview.git/blob - pv/mainwindow.cpp
6d28194bb87cbed491e00a3aa2bc21436e8976b3
[pulseview.git] / pv / mainwindow.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include <cassert>
22
23 #ifdef ENABLE_DECODE
24 #include <libsigrokdecode/libsigrokdecode.h>
25 #endif
26
27 #include <algorithm>
28 #include <iterator>
29
30 #include <boost/algorithm/string/join.hpp>
31
32 #include <QAction>
33 #include <QApplication>
34 #include <QButtonGroup>
35 #include <QCloseEvent>
36 #include <QFileDialog>
37 #include <QMessageBox>
38 #include <QMenu>
39 #include <QMenuBar>
40 #include <QSettings>
41 #include <QStatusBar>
42 #include <QVBoxLayout>
43 #include <QWidget>
44
45 #include "mainwindow.hpp"
46
47 #include "devicemanager.hpp"
48 #include "devices/hardwaredevice.hpp"
49 #include "devices/inputfile.hpp"
50 #include "devices/sessionfile.hpp"
51 #include "dialogs/about.hpp"
52 #include "dialogs/connect.hpp"
53 #include "dialogs/inputoutputoptions.hpp"
54 #include "dialogs/storeprogress.hpp"
55 #include "toolbars/mainbar.hpp"
56 #include "view/logicsignal.hpp"
57 #include "view/view.hpp"
58 #include "widgets/exportmenu.hpp"
59 #include "widgets/importmenu.hpp"
60 #ifdef ENABLE_DECODE
61 #include "widgets/decodermenu.hpp"
62 #endif
63 #include "widgets/hidingmenubar.hpp"
64
65 #include <inttypes.h>
66 #include <stdint.h>
67 #include <stdarg.h>
68 #include <glib.h>
69 #include <libsigrokcxx/libsigrokcxx.hpp>
70
71 using std::cerr;
72 using std::endl;
73 using std::list;
74 using std::map;
75 using std::pair;
76 using std::shared_ptr;
77 using std::string;
78 using std::vector;
79
80 using boost::algorithm::join;
81
82 using sigrok::Error;
83 using sigrok::OutputFormat;
84 using sigrok::InputFormat;
85
86 namespace pv {
87
88 namespace view {
89 class ViewItem;
90 }
91
92 const char *MainWindow::SettingOpenDirectory = "MainWindow/OpenDirectory";
93 const char *MainWindow::SettingSaveDirectory = "MainWindow/SaveDirectory";
94
95 MainWindow::MainWindow(DeviceManager &device_manager,
96         string open_file_name, string open_file_format,
97         QWidget *parent) :
98         QMainWindow(parent),
99         device_manager_(device_manager),
100         session_(device_manager),
101         action_open_(new QAction(this)),
102         action_save_as_(new QAction(this)),
103         action_connect_(new QAction(this)),
104         action_quit_(new QAction(this)),
105         action_view_zoom_in_(new QAction(this)),
106         action_view_zoom_out_(new QAction(this)),
107         action_view_zoom_fit_(new QAction(this)),
108         action_view_zoom_one_to_one_(new QAction(this)),
109         action_view_sticky_scrolling_(new QAction(this)),
110         action_view_show_cursors_(new QAction(this)),
111         action_about_(new QAction(this))
112 #ifdef ENABLE_DECODE
113         , menu_decoders_add_(new pv::widgets::DecoderMenu(this, true))
114 #endif
115 {
116         setup_ui();
117         restore_ui_settings();
118         if (open_file_name.empty())
119                 select_init_device();
120         else
121                 load_init_file(open_file_name, open_file_format);
122 }
123
124 QAction* MainWindow::action_open() const
125 {
126         return action_open_;
127 }
128
129 QAction* MainWindow::action_save_as() const
130 {
131         return action_save_as_;
132 }
133
134 QAction* MainWindow::action_connect() const
135 {
136         return action_connect_;
137 }
138
139 QAction* MainWindow::action_quit() const
140 {
141         return action_quit_;
142 }
143
144 QAction* MainWindow::action_view_zoom_in() const
145 {
146         return action_view_zoom_in_;
147 }
148
149 QAction* MainWindow::action_view_zoom_out() const
150 {
151         return action_view_zoom_out_;
152 }
153
154 QAction* MainWindow::action_view_zoom_fit() const
155 {
156         return action_view_zoom_fit_;
157 }
158
159 QAction* MainWindow::action_view_zoom_one_to_one() const
160 {
161         return action_view_zoom_one_to_one_;
162 }
163
164 QAction* MainWindow::action_view_sticky_scrolling() const
165 {
166         return action_view_sticky_scrolling_;
167 }
168
169 QAction* MainWindow::action_view_show_cursors() const
170 {
171         return action_view_show_cursors_;
172 }
173
174 QAction* MainWindow::action_about() const
175 {
176         return action_about_;
177 }
178
179 #ifdef ENABLE_DECODE
180 QMenu* MainWindow::menu_decoder_add() const
181 {
182         return menu_decoders_add_;
183 }
184 #endif
185
186 void MainWindow::run_stop()
187 {
188         switch(session_.get_capture_state()) {
189         case Session::Stopped:
190                 session_.start_capture([&](QString message) {
191                         session_error("Capture failed", message); });
192                 break;
193
194         case Session::AwaitingTrigger:
195         case Session::Running:
196                 session_.stop_capture();
197                 break;
198         }
199 }
200
201 void MainWindow::select_device(shared_ptr<devices::Device> device)
202 {
203         try {
204                 if (device)
205                         session_.set_device(device);
206                 else
207                         session_.set_default_device();
208         } catch(const QString &e) {
209                 QMessageBox msg(this);
210                 msg.setText(e);
211                 msg.setInformativeText(tr("Failed to Select Device"));
212                 msg.setStandardButtons(QMessageBox::Ok);
213                 msg.setIcon(QMessageBox::Warning);
214                 msg.exec();
215         }
216 }
217
218 void MainWindow::export_file(shared_ptr<OutputFormat> format)
219 {
220         using pv::dialogs::StoreProgress;
221
222         // Stop any currently running capture session
223         session_.stop_capture();
224
225         QSettings settings;
226         const QString dir = settings.value(SettingSaveDirectory).toString();
227
228         // Construct the filter
229         const vector<string> exts = format->extensions();
230         QString filter = tr("%1 files ").arg(
231                 QString::fromStdString(format->description()));
232
233         if (exts.empty())
234                 filter += "(*.*)";
235         else
236                 filter += QString("(*.%1);;%2 (*.*)").arg(
237                         QString::fromStdString(join(exts, ", *."))).arg(
238                         tr("All Files"));
239
240         // Show the file dialog
241         const QString file_name = QFileDialog::getSaveFileName(
242                 this, tr("Save File"), dir, filter);
243
244         if (file_name.isEmpty())
245                 return;
246
247         const QString abs_path = QFileInfo(file_name).absolutePath();
248         settings.setValue(SettingSaveDirectory, abs_path);
249
250         // Show the options dialog
251         map<string, Glib::VariantBase> options;
252         if (!format->options().empty()) {
253                 dialogs::InputOutputOptions dlg(
254                         tr("Export %1").arg(QString::fromStdString(
255                                 format->description())),
256                         format->options(), this);
257                 if (!dlg.exec())
258                         return;
259                 options = dlg.options();
260         }
261
262         StoreProgress *dlg = new StoreProgress(file_name, format, options,
263                 session_, this);
264         dlg->run();
265 }
266
267 void MainWindow::import_file(shared_ptr<InputFormat> format)
268 {
269         assert(format);
270
271         QSettings settings;
272         const QString dir = settings.value(SettingOpenDirectory).toString();
273
274         // Construct the filter
275         const vector<string> exts = format->extensions();
276         const QString filter = exts.empty() ? "" :
277                 tr("%1 files (*.%2)").arg(
278                         QString::fromStdString(format->description())).arg(
279                         QString::fromStdString(join(exts, ", *.")));
280
281         // Show the file dialog
282         const QString file_name = QFileDialog::getOpenFileName(
283                 this, tr("Import File"), dir, tr(
284                         "%1 files (*.*);;All Files (*.*)").arg(
285                         QString::fromStdString(format->description())));
286
287         if (file_name.isEmpty())
288                 return;
289
290         // Show the options dialog
291         map<string, Glib::VariantBase> options;
292         if (!format->options().empty()) {
293                 dialogs::InputOutputOptions dlg(
294                         tr("Import %1").arg(QString::fromStdString(
295                                 format->description())),
296                         format->options(), this);
297                 if (!dlg.exec())
298                         return;
299                 options = dlg.options();
300         }
301
302         load_file(file_name, format, options);
303
304         const QString abs_path = QFileInfo(file_name).absolutePath();
305         settings.setValue(SettingOpenDirectory, abs_path);
306 }
307
308 void MainWindow::setup_ui()
309 {
310         setObjectName(QString::fromUtf8("MainWindow"));
311
312         // Set the window icon
313         QIcon icon;
314         icon.addFile(QString(":/icons/sigrok-logo-notext.svg"));
315         setWindowIcon(icon);
316
317         // Setup the central widget
318         central_widget_ = new QWidget(this);
319         vertical_layout_ = new QVBoxLayout(central_widget_);
320         vertical_layout_->setSpacing(6);
321         vertical_layout_->setContentsMargins(0, 0, 0, 0);
322         setCentralWidget(central_widget_);
323
324         view_ = new pv::view::View(session_, this);
325
326         vertical_layout_->addWidget(view_);
327
328         // Setup the menu bar
329         pv::widgets::HidingMenuBar *const menu_bar =
330                 new pv::widgets::HidingMenuBar(this);
331
332         // File Menu
333         QMenu *const menu_file = new QMenu;
334         menu_file->setTitle(tr("&File"));
335
336         action_open_->setText(tr("&Open..."));
337         action_open_->setIcon(QIcon::fromTheme("document-open",
338                 QIcon(":/icons/document-open.png")));
339         action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
340         action_open_->setObjectName(QString::fromUtf8("actionOpen"));
341         menu_file->addAction(action_open_);
342
343         action_save_as_->setText(tr("&Save As..."));
344         action_save_as_->setIcon(QIcon::fromTheme("document-save-as",
345                 QIcon(":/icons/document-save-as.png")));
346         action_save_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
347         action_save_as_->setObjectName(QString::fromUtf8("actionSaveAs"));
348         menu_file->addAction(action_save_as_);
349
350         menu_file->addSeparator();
351
352         widgets::ExportMenu *menu_file_export = new widgets::ExportMenu(this,
353                 device_manager_.context());
354         menu_file_export->setTitle(tr("&Export"));
355         connect(menu_file_export,
356                 SIGNAL(format_selected(std::shared_ptr<sigrok::OutputFormat>)),
357                 this, SLOT(export_file(std::shared_ptr<sigrok::OutputFormat>)));
358         menu_file->addAction(menu_file_export->menuAction());
359
360         widgets::ImportMenu *menu_file_import = new widgets::ImportMenu(this,
361                 device_manager_.context());
362         menu_file_import->setTitle(tr("&Import"));
363         connect(menu_file_import,
364                 SIGNAL(format_selected(std::shared_ptr<sigrok::InputFormat>)),
365                 this, SLOT(import_file(std::shared_ptr<sigrok::InputFormat>)));
366         menu_file->addAction(menu_file_import->menuAction());
367
368         menu_file->addSeparator();
369
370         action_connect_->setText(tr("&Connect to Device..."));
371         action_connect_->setObjectName(QString::fromUtf8("actionConnect"));
372         menu_file->addAction(action_connect_);
373
374         menu_file->addSeparator();
375
376         action_quit_->setText(tr("&Quit"));
377         action_quit_->setIcon(QIcon::fromTheme("application-exit",
378                 QIcon(":/icons/application-exit.png")));
379         action_quit_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
380         action_quit_->setObjectName(QString::fromUtf8("actionQuit"));
381         menu_file->addAction(action_quit_);
382
383         // View Menu
384         QMenu *menu_view = new QMenu;
385         menu_view->setTitle(tr("&View"));
386
387         action_view_zoom_in_->setText(tr("Zoom &In"));
388         action_view_zoom_in_->setIcon(QIcon::fromTheme("zoom-in",
389                 QIcon(":/icons/zoom-in.png")));
390         // simply using Qt::Key_Plus shows no + in the menu
391         action_view_zoom_in_->setShortcut(QKeySequence::ZoomIn);
392         action_view_zoom_in_->setObjectName(
393                 QString::fromUtf8("actionViewZoomIn"));
394         menu_view->addAction(action_view_zoom_in_);
395
396         action_view_zoom_out_->setText(tr("Zoom &Out"));
397         action_view_zoom_out_->setIcon(QIcon::fromTheme("zoom-out",
398                 QIcon(":/icons/zoom-out.png")));
399         action_view_zoom_out_->setShortcut(QKeySequence::ZoomOut);
400         action_view_zoom_out_->setObjectName(
401                 QString::fromUtf8("actionViewZoomOut"));
402         menu_view->addAction(action_view_zoom_out_);
403
404         action_view_zoom_fit_->setText(tr("Zoom to &Fit"));
405         action_view_zoom_fit_->setIcon(QIcon::fromTheme("zoom-fit",
406                 QIcon(":/icons/zoom-fit.png")));
407         action_view_zoom_fit_->setShortcut(QKeySequence(Qt::Key_F));
408         action_view_zoom_fit_->setObjectName(
409                 QString::fromUtf8("actionViewZoomFit"));
410         menu_view->addAction(action_view_zoom_fit_);
411
412         action_view_zoom_one_to_one_->setText(tr("Zoom to O&ne-to-One"));
413         action_view_zoom_one_to_one_->setIcon(QIcon::fromTheme("zoom-original",
414                 QIcon(":/icons/zoom-original.png")));
415         action_view_zoom_one_to_one_->setShortcut(QKeySequence(Qt::Key_O));
416         action_view_zoom_one_to_one_->setObjectName(
417                 QString::fromUtf8("actionViewZoomOneToOne"));
418         menu_view->addAction(action_view_zoom_one_to_one_);
419
420         menu_file->addSeparator();
421
422         action_view_sticky_scrolling_->setCheckable(true);
423         action_view_sticky_scrolling_->setChecked(true);
424         action_view_sticky_scrolling_->setShortcut(QKeySequence(Qt::Key_R));
425         action_view_sticky_scrolling_->setObjectName(
426                 QString::fromUtf8("actionViewStickyScrolling"));
427         action_view_sticky_scrolling_->setText(tr("Sticky Sc&rolling"));
428         menu_view->addAction(action_view_sticky_scrolling_);
429
430         view_->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked());
431
432         menu_view->addSeparator();
433
434         action_view_show_cursors_->setCheckable(true);
435         action_view_show_cursors_->setChecked(view_->cursors_shown());
436         action_view_show_cursors_->setIcon(QIcon::fromTheme("show-cursors",
437                 QIcon(":/icons/show-cursors.svg")));
438         action_view_show_cursors_->setShortcut(QKeySequence(Qt::Key_C));
439         action_view_show_cursors_->setObjectName(
440                 QString::fromUtf8("actionViewShowCursors"));
441         action_view_show_cursors_->setText(tr("Show &Cursors"));
442         menu_view->addAction(action_view_show_cursors_);
443
444         // Decoders Menu
445 #ifdef ENABLE_DECODE
446         QMenu *const menu_decoders = new QMenu;
447         menu_decoders->setTitle(tr("&Decoders"));
448
449         menu_decoders_add_->setTitle(tr("&Add"));
450         connect(menu_decoders_add_, SIGNAL(decoder_selected(srd_decoder*)),
451                 this, SLOT(add_decoder(srd_decoder*)));
452
453         menu_decoders->addMenu(menu_decoders_add_);
454 #endif
455
456         // Help Menu
457         QMenu *const menu_help = new QMenu;
458         menu_help->setTitle(tr("&Help"));
459
460         action_about_->setObjectName(QString::fromUtf8("actionAbout"));
461         action_about_->setText(tr("&About..."));
462         menu_help->addAction(action_about_);
463
464         menu_bar->addAction(menu_file->menuAction());
465         menu_bar->addAction(menu_view->menuAction());
466 #ifdef ENABLE_DECODE
467         menu_bar->addAction(menu_decoders->menuAction());
468 #endif
469         menu_bar->addAction(menu_help->menuAction());
470
471         setMenuBar(menu_bar);
472         QMetaObject::connectSlotsByName(this);
473
474         // Also add all actions to the main window for always-enabled hotkeys
475         for (QAction* action : menu_bar->actions())
476                 this->addAction(action);
477
478         // Setup the toolbar
479         main_bar_ = new toolbars::MainBar(session_, *this);
480
481         // Populate the device list and select the initially selected device
482         update_device_list();
483
484         addToolBar(main_bar_);
485
486         // Set the title
487         setWindowTitle(tr("PulseView"));
488
489         // Setup session_ events
490         connect(&session_, SIGNAL(capture_state_changed(int)), this,
491                 SLOT(capture_state_changed(int)));
492         connect(&session_, SIGNAL(device_selected()), this,
493                 SLOT(device_selected()));
494
495         // Setup view_ events
496         connect(view_, SIGNAL(sticky_scrolling_changed(bool)), this,
497                 SLOT(sticky_scrolling_changed(bool)));
498
499 }
500
501 void MainWindow::select_init_device() {
502         QSettings settings;
503         map<string, string> dev_info;
504         list<string> key_list;
505
506         // Re-select last used device if possible.
507         settings.beginGroup("Device");
508         key_list.push_back("vendor");
509         key_list.push_back("model");
510         key_list.push_back("version");
511         key_list.push_back("serial_num");
512         key_list.push_back("connection_id");
513
514         for (string key : key_list) {
515                 const QString k = QString::fromStdString(key);
516                 if (!settings.contains(k))
517                         continue;
518
519                 const string value = settings.value(k).toString().toStdString();
520                 if (!value.empty())
521                         dev_info.insert(std::make_pair(key, value));
522         }
523
524         const shared_ptr<devices::HardwareDevice> device =
525                 device_manager_.find_device_from_info(dev_info);
526         select_device(device);
527         update_device_list();
528
529         settings.endGroup();
530 }
531
532 void MainWindow::load_init_file(const std::string &file_name,
533         const std::string &format) {
534         shared_ptr<InputFormat> input_format;
535
536         if (!format.empty()) {
537                 const map<string, shared_ptr<InputFormat> > formats =
538                         device_manager_.context()->input_formats();
539                 const auto iter = find_if(formats.begin(), formats.end(),
540                         [&](const pair<string, shared_ptr<InputFormat> > f) {
541                                 return f.first == format; });
542                 if (iter == formats.end()) {
543                         cerr << "Unexpected input format: " << format << endl;
544                         return;
545                 }
546
547                 input_format = (*iter).second;
548         }
549
550         load_file(QString::fromStdString(file_name), input_format);
551 }
552
553
554 void MainWindow::save_ui_settings()
555 {
556         QSettings settings;
557
558         map<string, string> dev_info;
559         list<string> key_list;
560
561         settings.beginGroup("MainWindow");
562         settings.setValue("state", saveState());
563         settings.setValue("geometry", saveGeometry());
564         settings.endGroup();
565
566         if (session_.device()) {
567                 settings.beginGroup("Device");
568                 key_list.push_back("vendor");
569                 key_list.push_back("model");
570                 key_list.push_back("version");
571                 key_list.push_back("serial_num");
572                 key_list.push_back("connection_id");
573
574                 dev_info = device_manager_.get_device_info(
575                         session_.device());
576
577                 for (string key : key_list) {
578
579                         if (dev_info.count(key))
580                                 settings.setValue(QString::fromUtf8(key.c_str()),
581                                                 QString::fromUtf8(dev_info.at(key).c_str()));
582                         else
583                                 settings.remove(QString::fromUtf8(key.c_str()));
584                 }
585
586                 settings.endGroup();
587         }
588 }
589
590 void MainWindow::restore_ui_settings()
591 {
592         QSettings settings;
593
594         settings.beginGroup("MainWindow");
595
596         if (settings.contains("geometry")) {
597                 restoreGeometry(settings.value("geometry").toByteArray());
598                 restoreState(settings.value("state").toByteArray());
599         } else
600                 resize(1000, 720);
601
602         settings.endGroup();
603 }
604
605 void MainWindow::session_error(
606         const QString text, const QString info_text)
607 {
608         QMetaObject::invokeMethod(this, "show_session_error",
609                 Qt::QueuedConnection, Q_ARG(QString, text),
610                 Q_ARG(QString, info_text));
611 }
612
613 void MainWindow::update_device_list()
614 {
615         main_bar_->update_device_list();
616 }
617
618 void MainWindow::load_file(QString file_name,
619         std::shared_ptr<sigrok::InputFormat> format,
620         const std::map<std::string, Glib::VariantBase> &options)
621 {
622         const QString errorMessage(
623                 QString("Failed to load file %1").arg(file_name));
624         const QString infoMessage;
625
626         try {
627                 if (format)
628                         session_.set_device(shared_ptr<devices::Device>(
629                                 new devices::InputFile(
630                                         device_manager_.context(),
631                                         file_name.toStdString(),
632                                         format, options)));
633                 else
634                         session_.set_device(shared_ptr<devices::Device>(
635                                 new devices::SessionFile(
636                                         device_manager_.context(),
637                                         file_name.toStdString())));
638         } catch(Error e) {
639                 show_session_error(tr("Failed to load ") + file_name, e.what());
640                 session_.set_default_device();
641                 update_device_list();
642                 return;
643         }
644
645         update_device_list();
646
647         session_.start_capture([&, errorMessage, infoMessage](QString) {
648                 session_error(errorMessage, infoMessage); });
649 }
650
651 void MainWindow::closeEvent(QCloseEvent *event)
652 {
653         save_ui_settings();
654         event->accept();
655 }
656
657 void MainWindow::keyReleaseEvent(QKeyEvent *event)
658 {
659         if (event->key() == Qt::Key_Alt) {
660                 menuBar()->setHidden(!menuBar()->isHidden());
661                 menuBar()->setFocus();
662         }
663         QMainWindow::keyReleaseEvent(event);
664 }
665
666 void MainWindow::show_session_error(
667         const QString text, const QString info_text)
668 {
669         QMessageBox msg(this);
670         msg.setText(text);
671         msg.setInformativeText(info_text);
672         msg.setStandardButtons(QMessageBox::Ok);
673         msg.setIcon(QMessageBox::Warning);
674         msg.exec();
675 }
676
677 void MainWindow::on_actionOpen_triggered()
678 {
679         QSettings settings;
680         const QString dir = settings.value(SettingOpenDirectory).toString();
681
682         // Show the dialog
683         const QString file_name = QFileDialog::getOpenFileName(
684                 this, tr("Open File"), dir, tr(
685                         "Sigrok Sessions (*.sr);;"
686                         "All Files (*.*)"));
687
688         if (!file_name.isEmpty()) {
689                 load_file(file_name);
690
691                 const QString abs_path = QFileInfo(file_name).absolutePath();
692                 settings.setValue(SettingOpenDirectory, abs_path);
693         }
694 }
695
696 void MainWindow::on_actionSaveAs_triggered()
697 {
698         export_file(device_manager_.context()->output_formats()["srzip"]);
699 }
700
701 void MainWindow::on_actionConnect_triggered()
702 {
703         // Stop any currently running capture session
704         session_.stop_capture();
705
706         dialogs::Connect dlg(this, device_manager_);
707
708         // If the user selected a device, select it in the device list. Select the
709         // current device otherwise.
710         if (dlg.exec())
711                 select_device(dlg.get_selected_device());
712
713         update_device_list();
714 }
715
716 void MainWindow::on_actionQuit_triggered()
717 {
718         close();
719 }
720
721 void MainWindow::on_actionViewZoomIn_triggered()
722 {
723         view_->zoom(1);
724 }
725
726 void MainWindow::on_actionViewZoomOut_triggered()
727 {
728         view_->zoom(-1);
729 }
730
731 void MainWindow::on_actionViewZoomFit_triggered()
732 {
733         view_->zoom_fit();
734 }
735
736 void MainWindow::on_actionViewZoomOneToOne_triggered()
737 {
738         view_->zoom_one_to_one();
739 }
740
741 void MainWindow::on_actionViewStickyScrolling_triggered()
742 {
743         view_->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked());
744 }
745
746 void MainWindow::on_actionViewShowCursors_triggered()
747 {
748         assert(view_);
749
750         const bool show = !view_->cursors_shown();
751         if(show)
752                 view_->centre_cursors();
753
754         view_->show_cursors(show);
755 }
756
757 void MainWindow::on_actionAbout_triggered()
758 {
759         dialogs::About dlg(device_manager_.context(), this);
760         dlg.exec();
761 }
762
763 void MainWindow::sticky_scrolling_changed(bool state)
764 {
765         action_view_sticky_scrolling_->setChecked(state);
766 }
767
768 void MainWindow::add_decoder(srd_decoder *decoder)
769 {
770 #ifdef ENABLE_DECODE
771         assert(decoder);
772         session_.add_decoder(decoder);
773 #else
774         (void)decoder;
775 #endif
776 }
777
778 void MainWindow::capture_state_changed(int state)
779 {
780         main_bar_->set_capture_state((pv::Session::capture_state)state);
781 }
782
783 void MainWindow::device_selected()
784 {
785         // Set the title to include the device/file name
786         const shared_ptr<devices::Device> device = session_.device();
787         if (!device)
788                 return;
789
790         const string display_name = device->display_name(device_manager_);
791         setWindowTitle(tr("%1 - PulseView").arg(display_name.c_str()));
792 }
793
794 } // namespace pv