]> sigrok.org Git - pulseview.git/blame - pv/mainwindow.cpp
MainWindow: Added format parameters to load_file
[pulseview.git] / pv / mainwindow.cpp
CommitLineData
d7bed479 1/*
b3f22de0 2 * This file is part of the PulseView project.
d7bed479
JH
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
943edd76
MC
21#include <cassert>
22
269528f5 23#ifdef ENABLE_DECODE
aaabd61b 24#include <libsigrokdecode/libsigrokdecode.h>
269528f5 25#endif
30236a54 26
85843b14
JH
27#include <algorithm>
28#include <iterator>
29
ea2dbfea
JH
30#include <boost/algorithm/string/join.hpp>
31
7d5425ef
JH
32#include <QAction>
33#include <QApplication>
34#include <QButtonGroup>
93f683ad 35#include <QCloseEvent>
2953961c 36#include <QFileDialog>
f2edb557 37#include <QMessageBox>
7d5425ef
JH
38#include <QMenu>
39#include <QMenuBar>
643f65f9 40#include <QSettings>
7d5425ef
JH
41#include <QStatusBar>
42#include <QVBoxLayout>
43#include <QWidget>
2953961c 44
2acdb232 45#include "mainwindow.hpp"
107ca6d3 46
2acdb232 47#include "devicemanager.hpp"
da30ecb7 48#include "devices/hardwaredevice.hpp"
dd3fd4df 49#include "devices/inputfile.hpp"
da30ecb7 50#include "devices/sessionfile.hpp"
2acdb232
JH
51#include "dialogs/about.hpp"
52#include "dialogs/connect.hpp"
e93f5538 53#include "dialogs/inputoutputoptions.hpp"
2acdb232 54#include "dialogs/storeprogress.hpp"
7c657094 55#include "toolbars/mainbar.hpp"
2acdb232
JH
56#include "view/logicsignal.hpp"
57#include "view/view.hpp"
998b89fd 58#include "widgets/exportmenu.hpp"
269528f5 59#ifdef ENABLE_DECODE
2acdb232 60#include "widgets/decodermenu.hpp"
269528f5 61#endif
1c4c23b8 62#include "widgets/hidingmenubar.hpp"
d7bed479 63
30236a54
JH
64#include <inttypes.h>
65#include <stdint.h>
66#include <stdarg.h>
67#include <glib.h>
fe3a1c21 68#include <libsigrokcxx/libsigrokcxx.hpp>
e82fd481 69
819f4c25 70using std::list;
6842b5fc 71using std::map;
f9abf97e 72using std::shared_ptr;
6842b5fc 73using std::string;
ea2dbfea
JH
74using std::vector;
75
76using boost::algorithm::join;
30236a54 77
e8d00928 78using sigrok::Error;
998b89fd 79using sigrok::OutputFormat;
dd3fd4df 80using sigrok::InputFormat;
e8d00928 81
51e77110
JH
82namespace pv {
83
b1264f56 84namespace view {
26e3af6b 85class ViewItem;
b1264f56
JH
86}
87
643f65f9
JS
88const char *MainWindow::SettingOpenDirectory = "MainWindow/OpenDirectory";
89const char *MainWindow::SettingSaveDirectory = "MainWindow/SaveDirectory";
90
107ca6d3
JH
91MainWindow::MainWindow(DeviceManager &device_manager,
92 const char *open_file_name,
1d478458 93 QWidget *parent) :
107ca6d3 94 QMainWindow(parent),
8dbbc7f0 95 device_manager_(device_manager),
69654681
JH
96 session_(device_manager),
97 action_open_(new QAction(this)),
98 action_save_as_(new QAction(this)),
99 action_connect_(new QAction(this)),
100 action_quit_(new QAction(this)),
101 action_view_zoom_in_(new QAction(this)),
102 action_view_zoom_out_(new QAction(this)),
103 action_view_zoom_fit_(new QAction(this)),
104 action_view_zoom_one_to_one_(new QAction(this)),
105 action_view_show_cursors_(new QAction(this)),
e79171dc
BG
106 action_about_(new QAction(this))
107#ifdef ENABLE_DECODE
108 , menu_decoders_add_(new pv::widgets::DecoderMenu(this, true))
19be0af1 109#endif
d7bed479 110{
7d5425ef 111 setup_ui();
93f683ad 112 restore_ui_settings();
1d478458
JH
113 if (open_file_name) {
114 const QString s(QString::fromUtf8(open_file_name));
115 QMetaObject::invokeMethod(this, "load_file",
116 Qt::QueuedConnection,
117 Q_ARG(QString, s));
118 }
7d5425ef
JH
119}
120
69654681
JH
121QAction* MainWindow::action_open() const
122{
123 return action_open_;
124}
125
126QAction* MainWindow::action_save_as() const
127{
128 return action_save_as_;
129}
130
131QAction* MainWindow::action_connect() const
132{
133 return action_connect_;
134}
135
136QAction* MainWindow::action_quit() const
137{
138 return action_quit_;
139}
140
141QAction* MainWindow::action_view_zoom_in() const
142{
143 return action_view_zoom_in_;
144}
145
146QAction* MainWindow::action_view_zoom_out() const
147{
148 return action_view_zoom_out_;
149}
150
151QAction* MainWindow::action_view_zoom_fit() const
152{
153 return action_view_zoom_fit_;
154}
155
156QAction* MainWindow::action_view_zoom_one_to_one() const
157{
158 return action_view_zoom_one_to_one_;
159}
160
161QAction* MainWindow::action_view_show_cursors() const
162{
163 return action_view_show_cursors_;
164}
165
166QAction* MainWindow::action_about() const
167{
168 return action_about_;
169}
170
e79171dc 171#ifdef ENABLE_DECODE
0f90452b
JH
172QMenu* MainWindow::menu_decoder_add() const
173{
174 return menu_decoders_add_;
175}
19be0af1 176#endif
0f90452b 177
4e7f5ba8
JH
178void MainWindow::run_stop()
179{
180 switch(session_.get_capture_state()) {
2b81ae46 181 case Session::Stopped:
4e7f5ba8
JH
182 session_.start_capture([&](QString message) {
183 session_error("Capture failed", message); });
184 break;
185
2b81ae46
JH
186 case Session::AwaitingTrigger:
187 case Session::Running:
4e7f5ba8
JH
188 session_.stop_capture();
189 break;
190 }
191}
192
da30ecb7 193void MainWindow::select_device(shared_ptr<devices::Device> device)
51cf49fe
JH
194{
195 try {
196 session_.set_device(device);
197 } catch(const QString &e) {
198 QMessageBox msg(this);
199 msg.setText(e);
200 msg.setInformativeText(tr("Failed to Select Device"));
201 msg.setStandardButtons(QMessageBox::Ok);
202 msg.setIcon(QMessageBox::Warning);
203 msg.exec();
204 }
205}
206
998b89fd
JH
207void MainWindow::export_file(shared_ptr<OutputFormat> format)
208{
209 using pv::dialogs::StoreProgress;
210
211 // Stop any currently running capture session
212 session_.stop_capture();
213
214 QSettings settings;
215 const QString dir = settings.value(SettingSaveDirectory).toString();
216
ea2dbfea
JH
217 // Construct the filter
218 const vector<string> exts = format->extensions();
219 QString filter = tr("%1 files ").arg(
220 QString::fromStdString(format->description()));
221
222 if (exts.empty())
223 filter += "(*.*)";
224 else
225 filter += QString("(*.%1);;%2 (*.*)").arg(
226 QString::fromStdString(join(exts, ", *."))).arg(
227 tr("All Files"));
228
e93f5538 229 // Show the file dialog
998b89fd 230 const QString file_name = QFileDialog::getSaveFileName(
ea2dbfea 231 this, tr("Save File"), dir, filter);
998b89fd
JH
232
233 if (file_name.isEmpty())
234 return;
235
236 const QString abs_path = QFileInfo(file_name).absolutePath();
237 settings.setValue(SettingSaveDirectory, abs_path);
238
e93f5538
JH
239 // Show the options dialog
240 map<string, Glib::VariantBase> options;
241 if (!format->options().empty()) {
242 dialogs::InputOutputOptions dlg(
243 tr("Export %1").arg(QString::fromStdString(
244 format->description())),
245 format->options(), this);
246 if (!dlg.exec())
247 return;
248 options = dlg.options();
249 }
250
251 StoreProgress *dlg = new StoreProgress(file_name, format, options,
998b89fd
JH
252 session_, this);
253 dlg->run();
254}
255
7d5425ef
JH
256void MainWindow::setup_ui()
257{
258 setObjectName(QString::fromUtf8("MainWindow"));
259
7d5425ef
JH
260 // Set the window icon
261 QIcon icon;
4523c509 262 icon.addFile(QString(":/icons/sigrok-logo-notext.svg"));
7d5425ef
JH
263 setWindowIcon(icon);
264
e072efc8 265 // Setup the central widget
8dbbc7f0
JH
266 central_widget_ = new QWidget(this);
267 vertical_layout_ = new QVBoxLayout(central_widget_);
268 vertical_layout_->setSpacing(6);
269 vertical_layout_->setContentsMargins(0, 0, 0, 0);
270 setCentralWidget(central_widget_);
e072efc8 271
8dbbc7f0 272 view_ = new pv::view::View(session_, this);
b1264f56 273
8dbbc7f0 274 vertical_layout_->addWidget(view_);
e072efc8 275
ab1d13ee 276 // Setup the menu bar
1c4c23b8
JH
277 pv::widgets::HidingMenuBar *const menu_bar =
278 new pv::widgets::HidingMenuBar(this);
a429590b 279
ab1d13ee 280 // File Menu
ced1cc13 281 QMenu *const menu_file = new QMenu;
0a9fdca5 282 menu_file->setTitle(tr("&File"));
e072efc8 283
69654681
JH
284 action_open_->setText(tr("&Open..."));
285 action_open_->setIcon(QIcon::fromTheme("document-open",
362eea96 286 QIcon(":/icons/document-open.png")));
69654681
JH
287 action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
288 action_open_->setObjectName(QString::fromUtf8("actionOpen"));
289 menu_file->addAction(action_open_);
009e1503 290
69654681
JH
291 action_save_as_->setText(tr("&Save As..."));
292 action_save_as_->setIcon(QIcon::fromTheme("document-save-as",
0fbda3c2 293 QIcon(":/icons/document-save-as.png")));
69654681
JH
294 action_save_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
295 action_save_as_->setObjectName(QString::fromUtf8("actionSaveAs"));
296 menu_file->addAction(action_save_as_);
0fbda3c2 297
ced1cc13 298 menu_file->addSeparator();
2a032dcb 299
998b89fd
JH
300 widgets::ExportMenu *menu_file_export = new widgets::ExportMenu(this,
301 device_manager_.context());
302 menu_file_export->setTitle(tr("&Export"));
303 connect(menu_file_export,
304 SIGNAL(format_selected(std::shared_ptr<sigrok::OutputFormat>)),
305 this, SLOT(export_file(std::shared_ptr<sigrok::OutputFormat>)));
306 menu_file->addAction(menu_file_export->menuAction());
307
308 menu_file->addSeparator();
309
69654681
JH
310 action_connect_->setText(tr("&Connect to Device..."));
311 action_connect_->setObjectName(QString::fromUtf8("actionConnect"));
312 menu_file->addAction(action_connect_);
9663c82b 313
ced1cc13 314 menu_file->addSeparator();
9663c82b 315
69654681
JH
316 action_quit_->setText(tr("&Quit"));
317 action_quit_->setIcon(QIcon::fromTheme("application-exit",
2a032dcb 318 QIcon(":/icons/application-exit.png")));
69654681
JH
319 action_quit_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
320 action_quit_->setObjectName(QString::fromUtf8("actionQuit"));
321 menu_file->addAction(action_quit_);
2a032dcb 322
ab1d13ee 323 // View Menu
ced1cc13 324 QMenu *menu_view = new QMenu;
0a9fdca5 325 menu_view->setTitle(tr("&View"));
ab1d13ee 326
69654681
JH
327 action_view_zoom_in_->setText(tr("Zoom &In"));
328 action_view_zoom_in_->setIcon(QIcon::fromTheme("zoom-in",
ab1d13ee 329 QIcon(":/icons/zoom-in.png")));
d2899ad5 330 // simply using Qt::Key_Plus shows no + in the menu
69654681
JH
331 action_view_zoom_in_->setShortcut(QKeySequence::ZoomIn);
332 action_view_zoom_in_->setObjectName(
ab1d13ee 333 QString::fromUtf8("actionViewZoomIn"));
69654681 334 menu_view->addAction(action_view_zoom_in_);
ab1d13ee 335
69654681
JH
336 action_view_zoom_out_->setText(tr("Zoom &Out"));
337 action_view_zoom_out_->setIcon(QIcon::fromTheme("zoom-out",
ab1d13ee 338 QIcon(":/icons/zoom-out.png")));
69654681
JH
339 action_view_zoom_out_->setShortcut(QKeySequence::ZoomOut);
340 action_view_zoom_out_->setObjectName(
ab1d13ee 341 QString::fromUtf8("actionViewZoomOut"));
69654681 342 menu_view->addAction(action_view_zoom_out_);
ab1d13ee 343
69654681
JH
344 action_view_zoom_fit_->setText(tr("Zoom to &Fit"));
345 action_view_zoom_fit_->setIcon(QIcon::fromTheme("zoom-fit",
ca46b534 346 QIcon(":/icons/zoom-fit.png")));
69654681
JH
347 action_view_zoom_fit_->setShortcut(QKeySequence(Qt::Key_F));
348 action_view_zoom_fit_->setObjectName(
ca46b534 349 QString::fromUtf8("actionViewZoomFit"));
69654681 350 menu_view->addAction(action_view_zoom_fit_);
ca46b534 351
1c4c23b8 352 action_view_zoom_one_to_one_->setText(tr("Zoom to O&ne-to-One"));
69654681 353 action_view_zoom_one_to_one_->setIcon(QIcon::fromTheme("zoom-original",
d1e7d82c 354 QIcon(":/icons/zoom-original.png")));
69654681
JH
355 action_view_zoom_one_to_one_->setShortcut(QKeySequence(Qt::Key_O));
356 action_view_zoom_one_to_one_->setObjectName(
d1e7d82c 357 QString::fromUtf8("actionViewZoomOneToOne"));
69654681 358 menu_view->addAction(action_view_zoom_one_to_one_);
d1e7d82c 359
ced1cc13 360 menu_view->addSeparator();
ab1d13ee 361
69654681
JH
362 action_view_show_cursors_->setCheckable(true);
363 action_view_show_cursors_->setChecked(view_->cursors_shown());
587f1d15
JH
364 action_view_show_cursors_->setIcon(QIcon::fromTheme("show-cursors",
365 QIcon(":/icons/show-cursors.svg")));
69654681
JH
366 action_view_show_cursors_->setShortcut(QKeySequence(Qt::Key_C));
367 action_view_show_cursors_->setObjectName(
ab1d13ee 368 QString::fromUtf8("actionViewShowCursors"));
69654681
JH
369 action_view_show_cursors_->setText(tr("Show &Cursors"));
370 menu_view->addAction(action_view_show_cursors_);
a429590b 371
7dd093df 372 // Decoders Menu
269528f5 373#ifdef ENABLE_DECODE
ced1cc13 374 QMenu *const menu_decoders = new QMenu;
0a9fdca5 375 menu_decoders->setTitle(tr("&Decoders"));
7dd093df 376
0f90452b
JH
377 menu_decoders_add_->setTitle(tr("&Add"));
378 connect(menu_decoders_add_, SIGNAL(decoder_selected(srd_decoder*)),
f0d37dab 379 this, SLOT(add_decoder(srd_decoder*)));
7dd093df 380
0f90452b 381 menu_decoders->addMenu(menu_decoders_add_);
269528f5 382#endif
7dd093df 383
ab1d13ee 384 // Help Menu
ced1cc13 385 QMenu *const menu_help = new QMenu;
0a9fdca5 386 menu_help->setTitle(tr("&Help"));
ab1d13ee 387
69654681
JH
388 action_about_->setObjectName(QString::fromUtf8("actionAbout"));
389 action_about_->setText(tr("&About..."));
390 menu_help->addAction(action_about_);
7d5425ef 391
ced1cc13
JH
392 menu_bar->addAction(menu_file->menuAction());
393 menu_bar->addAction(menu_view->menuAction());
269528f5 394#ifdef ENABLE_DECODE
ced1cc13 395 menu_bar->addAction(menu_decoders->menuAction());
269528f5 396#endif
ced1cc13 397 menu_bar->addAction(menu_help->menuAction());
7d5425ef 398
ced1cc13 399 setMenuBar(menu_bar);
7d5425ef
JH
400 QMetaObject::connectSlotsByName(this);
401
d2f13e3e 402 // Setup the toolbar
7c657094 403 main_bar_ = new toolbars::MainBar(session_, *this);
5ac961e3
JH
404
405 // Populate the device list and select the initially selected device
107ca6d3 406 update_device_list();
5ac961e3 407
7c657094 408 addToolBar(main_bar_);
d4984fe7 409
5ac961e3 410 // Set the title
0a9fdca5 411 setWindowTitle(tr("PulseView"));
a8d3fb2d 412
8dbbc7f0
JH
413 // Setup session_ events
414 connect(&session_, SIGNAL(capture_state_changed(int)), this,
6ac96c2e 415 SLOT(capture_state_changed(int)));
20f81a58
JH
416 connect(&session_, SIGNAL(device_selected()), this,
417 SLOT(device_selected()));
d7bed479 418}
30236a54 419
93f683ad
SA
420void MainWindow::save_ui_settings()
421{
39eb0d45 422 QSettings settings;
93f683ad 423
6842b5fc
SA
424 map<string, string> dev_info;
425 list<string> key_list;
426
93f683ad
SA
427 settings.beginGroup("MainWindow");
428 settings.setValue("state", saveState());
429 settings.setValue("geometry", saveGeometry());
430 settings.endGroup();
6842b5fc 431
8dbbc7f0 432 if (session_.device()) {
6842b5fc
SA
433 settings.beginGroup("Device");
434 key_list.push_back("vendor");
435 key_list.push_back("model");
436 key_list.push_back("version");
437 key_list.push_back("serial_num");
438 key_list.push_back("connection_id");
439
8dbbc7f0
JH
440 dev_info = device_manager_.get_device_info(
441 session_.device());
6842b5fc
SA
442
443 for (string key : key_list) {
444
445 if (dev_info.count(key))
446 settings.setValue(QString::fromUtf8(key.c_str()),
447 QString::fromUtf8(dev_info.at(key).c_str()));
448 else
449 settings.remove(QString::fromUtf8(key.c_str()));
450 }
451
452 settings.endGroup();
453 }
93f683ad
SA
454}
455
456void MainWindow::restore_ui_settings()
457{
39eb0d45 458 QSettings settings;
93f683ad 459
6842b5fc
SA
460 map<string, string> dev_info;
461 list<string> key_list;
462 string value;
463
93f683ad
SA
464 settings.beginGroup("MainWindow");
465
466 if (settings.contains("geometry")) {
467 restoreGeometry(settings.value("geometry").toByteArray());
468 restoreState(settings.value("state").toByteArray());
469 } else
470 resize(1000, 720);
471
472 settings.endGroup();
6842b5fc
SA
473
474 // Re-select last used device if possible.
475 settings.beginGroup("Device");
476 key_list.push_back("vendor");
477 key_list.push_back("model");
478 key_list.push_back("version");
479 key_list.push_back("serial_num");
480 key_list.push_back("connection_id");
481
482 for (string key : key_list) {
483 if (!settings.contains(QString::fromUtf8(key.c_str())))
484 continue;
485
486 value = settings.value(QString::fromUtf8(key.c_str())).toString().toStdString();
487
488 if (value.size() > 0)
489 dev_info.insert(std::make_pair(key, value));
490 }
491
da30ecb7
JH
492 const shared_ptr<devices::HardwareDevice> device =
493 device_manager_.find_device_from_info(dev_info);
6842b5fc 494 if (device) {
51cf49fe 495 select_device(device);
6842b5fc
SA
496 update_device_list();
497 }
498
499 settings.endGroup();
93f683ad
SA
500}
501
f2edb557
JH
502void MainWindow::session_error(
503 const QString text, const QString info_text)
504{
505 QMetaObject::invokeMethod(this, "show_session_error",
506 Qt::QueuedConnection, Q_ARG(QString, text),
507 Q_ARG(QString, info_text));
508}
509
d873f4d6 510void MainWindow::update_device_list()
107ca6d3 511{
079d39ea 512 main_bar_->update_device_list();
107ca6d3
JH
513}
514
93f683ad
SA
515void MainWindow::closeEvent(QCloseEvent *event)
516{
517 save_ui_settings();
518 event->accept();
519}
520
1c4c23b8
JH
521void MainWindow::keyReleaseEvent(QKeyEvent *event)
522{
523 if (event->key() == Qt::Key_Alt) {
524 menuBar()->setHidden(!menuBar()->isHidden());
525 menuBar()->setFocus();
526 }
527 QMainWindow::keyReleaseEvent(event);
528}
529
dd3fd4df
JH
530void MainWindow::load_file(QString file_name,
531 std::shared_ptr<sigrok::InputFormat> format,
532 const std::map<std::string, Glib::VariantBase> &options)
1d478458 533{
f2edb557
JH
534 const QString errorMessage(
535 QString("Failed to load file %1").arg(file_name));
536 const QString infoMessage;
ae2d1bc5
JH
537
538 try {
dd3fd4df
JH
539 if (format)
540 session_.set_device(shared_ptr<devices::Device>(
541 new devices::InputFile(
542 device_manager_.context(),
543 file_name.toStdString(),
544 format, options)));
545 else
546 session_.set_device(shared_ptr<devices::Device>(
547 new devices::SessionFile(
548 device_manager_.context(),
549 file_name.toStdString())));
e8d00928
ML
550 } catch(Error e) {
551 show_session_error(tr("Failed to load ") + file_name, e.what());
8dbbc7f0 552 session_.set_default_device();
6fd0b639
JH
553 update_device_list();
554 return;
ae2d1bc5
JH
555 }
556
a5ea63c2
JH
557 update_device_list();
558
8dbbc7f0 559 session_.start_capture([&, errorMessage, infoMessage](QString) {
6db73158 560 session_error(errorMessage, infoMessage); });
f2edb557
JH
561}
562
563void MainWindow::show_session_error(
564 const QString text, const QString info_text)
565{
566 QMessageBox msg(this);
567 msg.setText(text);
568 msg.setInformativeText(info_text);
569 msg.setStandardButtons(QMessageBox::Ok);
570 msg.setIcon(QMessageBox::Warning);
571 msg.exec();
1d478458
JH
572}
573
2953961c
JH
574void MainWindow::on_actionOpen_triggered()
575{
643f65f9
JS
576 QSettings settings;
577 const QString dir = settings.value(SettingOpenDirectory).toString();
578
1d43d767 579 // Show the dialog
1d478458 580 const QString file_name = QFileDialog::getOpenFileName(
643f65f9 581 this, tr("Open File"), dir, tr(
6866d5de
JH
582 "Sigrok Sessions (*.sr);;"
583 "All Files (*.*)"));
643f65f9
JS
584
585 if (!file_name.isEmpty()) {
92b139d0 586 load_file(file_name);
643f65f9
JS
587
588 const QString abs_path = QFileInfo(file_name).absolutePath();
589 settings.setValue(SettingOpenDirectory, abs_path);
590 }
2953961c
JH
591}
592
0fbda3c2
JH
593void MainWindow::on_actionSaveAs_triggered()
594{
998b89fd 595 export_file(device_manager_.context()->output_formats()["srzip"]);
0fbda3c2
JH
596}
597
9663c82b
JH
598void MainWindow::on_actionConnect_triggered()
599{
b99cfc42 600 // Stop any currently running capture session
8dbbc7f0 601 session_.stop_capture();
b99cfc42 602
8dbbc7f0 603 dialogs::Connect dlg(this, device_manager_);
5eb0fa13 604
dc0867ff
JH
605 // If the user selected a device, select it in the device list. Select the
606 // current device otherwise.
d873f4d6 607 if (dlg.exec())
51cf49fe 608 select_device(dlg.get_selected_device());
dc0867ff 609
d873f4d6 610 update_device_list();
9663c82b
JH
611}
612
2a032dcb
JH
613void MainWindow::on_actionQuit_triggered()
614{
615 close();
616}
617
a429590b
JH
618void MainWindow::on_actionViewZoomIn_triggered()
619{
8dbbc7f0 620 view_->zoom(1);
a429590b
JH
621}
622
623void MainWindow::on_actionViewZoomOut_triggered()
624{
8dbbc7f0 625 view_->zoom(-1);
a429590b
JH
626}
627
ca46b534
JH
628void MainWindow::on_actionViewZoomFit_triggered()
629{
8dbbc7f0 630 view_->zoom_fit();
ca46b534
JH
631}
632
d1e7d82c
JH
633void MainWindow::on_actionViewZoomOneToOne_triggered()
634{
8dbbc7f0 635 view_->zoom_one_to_one();
d1e7d82c
JH
636}
637
e072efc8
JH
638void MainWindow::on_actionViewShowCursors_triggered()
639{
8dbbc7f0 640 assert(view_);
b4d91e56 641
8dbbc7f0 642 const bool show = !view_->cursors_shown();
b4d91e56 643 if(show)
8dbbc7f0 644 view_->centre_cursors();
b4d91e56 645
8dbbc7f0 646 view_->show_cursors(show);
e072efc8
JH
647}
648
30236a54
JH
649void MainWindow::on_actionAbout_triggered()
650{
8dbbc7f0 651 dialogs::About dlg(device_manager_.context(), this);
40eb2ff4 652 dlg.exec();
30236a54 653}
274d4f13 654
f0d37dab 655void MainWindow::add_decoder(srd_decoder *decoder)
7dd093df 656{
269528f5 657#ifdef ENABLE_DECODE
f0d37dab 658 assert(decoder);
8dbbc7f0 659 session_.add_decoder(decoder);
269528f5
JH
660#else
661 (void)decoder;
662#endif
7dd093df
JH
663}
664
6ac96c2e
JH
665void MainWindow::capture_state_changed(int state)
666{
7c657094 667 main_bar_->set_capture_state((pv::Session::capture_state)state);
6ac96c2e
JH
668}
669
20f81a58
JH
670void MainWindow::device_selected()
671{
672 // Set the title to include the device/file name
da30ecb7 673 const shared_ptr<devices::Device> device = session_.device();
20f81a58
JH
674 if (!device)
675 return;
676
3084ed4b 677 const string display_name = device->display_name(device_manager_);
20f81a58
JH
678 setWindowTitle(tr("%1 - PulseView").arg(display_name.c_str()));
679}
680
51e77110 681} // namespace pv