]>
Commit | Line | Data |
---|---|---|
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 | ||
7d5425ef JH |
30 | #include <QAction> |
31 | #include <QApplication> | |
32 | #include <QButtonGroup> | |
93f683ad | 33 | #include <QCloseEvent> |
2953961c | 34 | #include <QFileDialog> |
f2edb557 | 35 | #include <QMessageBox> |
7d5425ef JH |
36 | #include <QMenu> |
37 | #include <QMenuBar> | |
643f65f9 | 38 | #include <QSettings> |
7d5425ef JH |
39 | #include <QStatusBar> |
40 | #include <QVBoxLayout> | |
41 | #include <QWidget> | |
2953961c | 42 | |
d7bed479 | 43 | #include "mainwindow.h" |
107ca6d3 JH |
44 | |
45 | #include "devicemanager.h" | |
85843b14 | 46 | #include "device/device.h" |
acda14b8 | 47 | #include "dialogs/about.h" |
9663c82b | 48 | #include "dialogs/connect.h" |
0fbda3c2 | 49 | #include "dialogs/storeprogress.h" |
f4c92e1c | 50 | #include "toolbars/samplingbar.h" |
3045c869 | 51 | #include "view/logicsignal.h" |
4104d7f3 | 52 | #include "view/view.h" |
269528f5 | 53 | #ifdef ENABLE_DECODE |
f0d37dab | 54 | #include "widgets/decodermenu.h" |
269528f5 | 55 | #endif |
d7bed479 | 56 | |
30236a54 JH |
57 | /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */ |
58 | #define __STDC_FORMAT_MACROS | |
59 | #include <inttypes.h> | |
60 | #include <stdint.h> | |
61 | #include <stdarg.h> | |
62 | #include <glib.h> | |
63 | #include <libsigrok/libsigrok.h> | |
e82fd481 | 64 | |
819f4c25 | 65 | using std::list; |
6842b5fc | 66 | using std::map; |
f9abf97e | 67 | using std::shared_ptr; |
6842b5fc | 68 | using std::string; |
30236a54 | 69 | |
51e77110 JH |
70 | namespace pv { |
71 | ||
b1264f56 JH |
72 | namespace view { |
73 | class SelectableItem; | |
74 | } | |
75 | ||
643f65f9 JS |
76 | const char *MainWindow::SettingOpenDirectory = "MainWindow/OpenDirectory"; |
77 | const char *MainWindow::SettingSaveDirectory = "MainWindow/SaveDirectory"; | |
78 | ||
107ca6d3 JH |
79 | MainWindow::MainWindow(DeviceManager &device_manager, |
80 | const char *open_file_name, | |
1d478458 | 81 | QWidget *parent) : |
107ca6d3 | 82 | QMainWindow(parent), |
dc0867ff | 83 | _device_manager(device_manager), |
f0d37dab | 84 | _session(device_manager) |
d7bed479 | 85 | { |
7d5425ef | 86 | setup_ui(); |
93f683ad | 87 | restore_ui_settings(); |
1d478458 JH |
88 | if (open_file_name) { |
89 | const QString s(QString::fromUtf8(open_file_name)); | |
90 | QMetaObject::invokeMethod(this, "load_file", | |
91 | Qt::QueuedConnection, | |
92 | Q_ARG(QString, s)); | |
93 | } | |
7d5425ef JH |
94 | } |
95 | ||
96 | void MainWindow::setup_ui() | |
97 | { | |
98 | setObjectName(QString::fromUtf8("MainWindow")); | |
99 | ||
7d5425ef JH |
100 | // Set the window icon |
101 | QIcon icon; | |
102 | icon.addFile(QString::fromUtf8(":/icons/sigrok-logo-notext.png"), | |
103 | QSize(), QIcon::Normal, QIcon::Off); | |
104 | setWindowIcon(icon); | |
105 | ||
e072efc8 JH |
106 | // Setup the central widget |
107 | _central_widget = new QWidget(this); | |
108 | _vertical_layout = new QVBoxLayout(_central_widget); | |
109 | _vertical_layout->setSpacing(6); | |
110 | _vertical_layout->setContentsMargins(0, 0, 0, 0); | |
111 | setCentralWidget(_central_widget); | |
112 | ||
113 | _view = new pv::view::View(_session, this); | |
b1264f56 | 114 | |
e072efc8 JH |
115 | _vertical_layout->addWidget(_view); |
116 | ||
ab1d13ee | 117 | // Setup the menu bar |
ced1cc13 JH |
118 | QMenuBar *const menu_bar = new QMenuBar(this); |
119 | menu_bar->setGeometry(QRect(0, 0, 400, 25)); | |
a429590b | 120 | |
ab1d13ee | 121 | // File Menu |
ced1cc13 | 122 | QMenu *const menu_file = new QMenu; |
0a9fdca5 | 123 | menu_file->setTitle(tr("&File")); |
e072efc8 | 124 | |
ced1cc13 | 125 | QAction *const action_open = new QAction(this); |
0a9fdca5 | 126 | action_open->setText(tr("&Open...")); |
ced1cc13 | 127 | action_open->setIcon(QIcon::fromTheme("document-open", |
362eea96 | 128 | QIcon(":/icons/document-open.png"))); |
5117748b | 129 | action_open->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); |
ced1cc13 JH |
130 | action_open->setObjectName(QString::fromUtf8("actionOpen")); |
131 | menu_file->addAction(action_open); | |
009e1503 | 132 | |
0fbda3c2 | 133 | QAction *const action_save_as = new QAction(this); |
0a9fdca5 | 134 | action_save_as->setText(tr("&Save As...")); |
0fbda3c2 JH |
135 | action_save_as->setIcon(QIcon::fromTheme("document-save-as", |
136 | QIcon(":/icons/document-save-as.png"))); | |
5117748b | 137 | action_save_as->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); |
0fbda3c2 JH |
138 | action_save_as->setObjectName(QString::fromUtf8("actionSaveAs")); |
139 | menu_file->addAction(action_save_as); | |
140 | ||
ced1cc13 | 141 | menu_file->addSeparator(); |
2a032dcb | 142 | |
ced1cc13 | 143 | QAction *const action_connect = new QAction(this); |
0a9fdca5 | 144 | action_connect->setText(tr("&Connect to Device...")); |
ced1cc13 JH |
145 | action_connect->setObjectName(QString::fromUtf8("actionConnect")); |
146 | menu_file->addAction(action_connect); | |
9663c82b | 147 | |
ced1cc13 | 148 | menu_file->addSeparator(); |
9663c82b | 149 | |
ced1cc13 | 150 | QAction *action_quit = new QAction(this); |
0a9fdca5 | 151 | action_quit->setText(tr("&Quit")); |
ced1cc13 | 152 | action_quit->setIcon(QIcon::fromTheme("application-exit", |
2a032dcb | 153 | QIcon(":/icons/application-exit.png"))); |
ced1cc13 JH |
154 | action_quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q)); |
155 | action_quit->setObjectName(QString::fromUtf8("actionQuit")); | |
156 | menu_file->addAction(action_quit); | |
2a032dcb | 157 | |
ab1d13ee | 158 | // View Menu |
ced1cc13 | 159 | QMenu *menu_view = new QMenu; |
0a9fdca5 | 160 | menu_view->setTitle(tr("&View")); |
ab1d13ee | 161 | |
ced1cc13 | 162 | QAction *const action_view_zoom_in = new QAction(this); |
0a9fdca5 | 163 | action_view_zoom_in->setText(tr("Zoom &In")); |
ced1cc13 | 164 | action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in", |
ab1d13ee | 165 | QIcon(":/icons/zoom-in.png"))); |
d2899ad5 | 166 | // simply using Qt::Key_Plus shows no + in the menu |
167 | action_view_zoom_in->setShortcut(QKeySequence::ZoomIn); | |
ced1cc13 | 168 | action_view_zoom_in->setObjectName( |
ab1d13ee | 169 | QString::fromUtf8("actionViewZoomIn")); |
ced1cc13 | 170 | menu_view->addAction(action_view_zoom_in); |
ab1d13ee | 171 | |
ced1cc13 | 172 | QAction *const action_view_zoom_out = new QAction(this); |
0a9fdca5 | 173 | action_view_zoom_out->setText(tr("Zoom &Out")); |
ced1cc13 | 174 | action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out", |
ab1d13ee | 175 | QIcon(":/icons/zoom-out.png"))); |
d2899ad5 | 176 | action_view_zoom_out->setShortcut(QKeySequence::ZoomOut); |
ced1cc13 | 177 | action_view_zoom_out->setObjectName( |
ab1d13ee | 178 | QString::fromUtf8("actionViewZoomOut")); |
ced1cc13 | 179 | menu_view->addAction(action_view_zoom_out); |
ab1d13ee | 180 | |
ca46b534 | 181 | QAction *const action_view_zoom_fit = new QAction(this); |
0a9fdca5 | 182 | action_view_zoom_fit->setText(tr("Zoom to &Fit")); |
ca46b534 JH |
183 | action_view_zoom_fit->setIcon(QIcon::fromTheme("zoom-fit", |
184 | QIcon(":/icons/zoom-fit.png"))); | |
185 | action_view_zoom_fit->setShortcut(QKeySequence(Qt::Key_F)); | |
186 | action_view_zoom_fit->setObjectName( | |
187 | QString::fromUtf8("actionViewZoomFit")); | |
188 | menu_view->addAction(action_view_zoom_fit); | |
189 | ||
d1e7d82c | 190 | QAction *const action_view_zoom_one_to_one = new QAction(this); |
0a9fdca5 | 191 | action_view_zoom_one_to_one->setText(tr("Zoom to &One-to-One")); |
d1e7d82c JH |
192 | action_view_zoom_one_to_one->setIcon(QIcon::fromTheme("zoom-original", |
193 | QIcon(":/icons/zoom-original.png"))); | |
194 | action_view_zoom_one_to_one->setShortcut(QKeySequence(Qt::Key_O)); | |
195 | action_view_zoom_one_to_one->setObjectName( | |
196 | QString::fromUtf8("actionViewZoomOneToOne")); | |
197 | menu_view->addAction(action_view_zoom_one_to_one); | |
198 | ||
ced1cc13 | 199 | menu_view->addSeparator(); |
ab1d13ee | 200 | |
ced1cc13 JH |
201 | QAction *action_view_show_cursors = new QAction(this); |
202 | action_view_show_cursors->setCheckable(true); | |
203 | action_view_show_cursors->setChecked(_view->cursors_shown()); | |
204 | action_view_show_cursors->setShortcut(QKeySequence(Qt::Key_C)); | |
205 | action_view_show_cursors->setObjectName( | |
ab1d13ee | 206 | QString::fromUtf8("actionViewShowCursors")); |
0a9fdca5 | 207 | action_view_show_cursors->setText(tr("Show &Cursors")); |
ced1cc13 | 208 | menu_view->addAction(action_view_show_cursors); |
a429590b | 209 | |
7dd093df | 210 | // Decoders Menu |
269528f5 | 211 | #ifdef ENABLE_DECODE |
ced1cc13 | 212 | QMenu *const menu_decoders = new QMenu; |
0a9fdca5 | 213 | menu_decoders->setTitle(tr("&Decoders")); |
7dd093df | 214 | |
ced1cc13 | 215 | pv::widgets::DecoderMenu *const menu_decoders_add = |
f69ec72d | 216 | new pv::widgets::DecoderMenu(menu_decoders, true); |
0a9fdca5 | 217 | menu_decoders_add->setTitle(tr("&Add")); |
ced1cc13 | 218 | connect(menu_decoders_add, SIGNAL(decoder_selected(srd_decoder*)), |
f0d37dab | 219 | this, SLOT(add_decoder(srd_decoder*))); |
7dd093df | 220 | |
ced1cc13 | 221 | menu_decoders->addMenu(menu_decoders_add); |
269528f5 | 222 | #endif |
7dd093df | 223 | |
ab1d13ee | 224 | // Help Menu |
ced1cc13 | 225 | QMenu *const menu_help = new QMenu; |
0a9fdca5 | 226 | menu_help->setTitle(tr("&Help")); |
ab1d13ee | 227 | |
ced1cc13 JH |
228 | QAction *const action_about = new QAction(this); |
229 | action_about->setObjectName(QString::fromUtf8("actionAbout")); | |
0a9fdca5 | 230 | action_about->setText(tr("&About...")); |
ced1cc13 | 231 | menu_help->addAction(action_about); |
7d5425ef | 232 | |
ced1cc13 JH |
233 | menu_bar->addAction(menu_file->menuAction()); |
234 | menu_bar->addAction(menu_view->menuAction()); | |
269528f5 | 235 | #ifdef ENABLE_DECODE |
ced1cc13 | 236 | menu_bar->addAction(menu_decoders->menuAction()); |
269528f5 | 237 | #endif |
ced1cc13 | 238 | menu_bar->addAction(menu_help->menuAction()); |
7d5425ef | 239 | |
ced1cc13 | 240 | setMenuBar(menu_bar); |
7d5425ef JH |
241 | QMetaObject::connectSlotsByName(this); |
242 | ||
5ac961e3 | 243 | // Setup the toolbar |
ced1cc13 | 244 | QToolBar *const toolbar = new QToolBar(tr("Main Toolbar"), this); |
0c7cdea2 | 245 | toolbar->setObjectName(QString::fromUtf8("MainToolbar")); |
ced1cc13 | 246 | toolbar->addAction(action_open); |
f45512cb | 247 | toolbar->addAction(action_save_as); |
ced1cc13 JH |
248 | toolbar->addSeparator(); |
249 | toolbar->addAction(action_view_zoom_in); | |
250 | toolbar->addAction(action_view_zoom_out); | |
ca46b534 | 251 | toolbar->addAction(action_view_zoom_fit); |
f45512cb | 252 | toolbar->addAction(action_view_zoom_one_to_one); |
ced1cc13 | 253 | addToolBar(toolbar); |
0a4db787 | 254 | |
5ac961e3 | 255 | // Setup the sampling bar |
aca00b1e | 256 | _sampling_bar = new toolbars::SamplingBar(_session, this); |
5ac961e3 JH |
257 | |
258 | // Populate the device list and select the initially selected device | |
107ca6d3 | 259 | update_device_list(); |
5ac961e3 | 260 | |
274d4f13 JH |
261 | connect(_sampling_bar, SIGNAL(run_stop()), this, |
262 | SLOT(run_stop())); | |
d4984fe7 JH |
263 | addToolBar(_sampling_bar); |
264 | ||
5ac961e3 | 265 | // Set the title |
0a9fdca5 | 266 | setWindowTitle(tr("PulseView")); |
a8d3fb2d | 267 | |
6ac96c2e JH |
268 | // Setup _session events |
269 | connect(&_session, SIGNAL(capture_state_changed(int)), this, | |
270 | SLOT(capture_state_changed(int))); | |
d7bed479 | 271 | } |
30236a54 | 272 | |
93f683ad SA |
273 | void MainWindow::save_ui_settings() |
274 | { | |
39eb0d45 | 275 | QSettings settings; |
93f683ad | 276 | |
6842b5fc SA |
277 | map<string, string> dev_info; |
278 | list<string> key_list; | |
279 | ||
93f683ad SA |
280 | settings.beginGroup("MainWindow"); |
281 | settings.setValue("state", saveState()); | |
282 | settings.setValue("geometry", saveGeometry()); | |
283 | settings.endGroup(); | |
6842b5fc SA |
284 | |
285 | if (_session.get_device()) { | |
286 | settings.beginGroup("Device"); | |
287 | key_list.push_back("vendor"); | |
288 | key_list.push_back("model"); | |
289 | key_list.push_back("version"); | |
290 | key_list.push_back("serial_num"); | |
291 | key_list.push_back("connection_id"); | |
292 | ||
293 | dev_info = _session.get_device()->get_device_info(); | |
294 | ||
295 | for (string key : key_list) { | |
296 | ||
297 | if (dev_info.count(key)) | |
298 | settings.setValue(QString::fromUtf8(key.c_str()), | |
299 | QString::fromUtf8(dev_info.at(key).c_str())); | |
300 | else | |
301 | settings.remove(QString::fromUtf8(key.c_str())); | |
302 | } | |
303 | ||
304 | settings.endGroup(); | |
305 | } | |
93f683ad SA |
306 | } |
307 | ||
308 | void MainWindow::restore_ui_settings() | |
309 | { | |
39eb0d45 | 310 | QSettings settings; |
93f683ad | 311 | |
6842b5fc SA |
312 | shared_ptr<pv::device::DevInst> device; |
313 | ||
314 | map<string, string> dev_info; | |
315 | list<string> key_list; | |
316 | string value; | |
317 | ||
93f683ad SA |
318 | settings.beginGroup("MainWindow"); |
319 | ||
320 | if (settings.contains("geometry")) { | |
321 | restoreGeometry(settings.value("geometry").toByteArray()); | |
322 | restoreState(settings.value("state").toByteArray()); | |
323 | } else | |
324 | resize(1000, 720); | |
325 | ||
326 | settings.endGroup(); | |
6842b5fc SA |
327 | |
328 | // Re-select last used device if possible. | |
329 | settings.beginGroup("Device"); | |
330 | key_list.push_back("vendor"); | |
331 | key_list.push_back("model"); | |
332 | key_list.push_back("version"); | |
333 | key_list.push_back("serial_num"); | |
334 | key_list.push_back("connection_id"); | |
335 | ||
336 | for (string key : key_list) { | |
337 | if (!settings.contains(QString::fromUtf8(key.c_str()))) | |
338 | continue; | |
339 | ||
340 | value = settings.value(QString::fromUtf8(key.c_str())).toString().toStdString(); | |
341 | ||
342 | if (value.size() > 0) | |
343 | dev_info.insert(std::make_pair(key, value)); | |
344 | } | |
345 | ||
346 | device = _device_manager.find_device_from_info(dev_info); | |
347 | ||
348 | if (device) { | |
349 | _session.set_device(device); | |
350 | update_device_list(); | |
351 | } | |
352 | ||
353 | settings.endGroup(); | |
93f683ad SA |
354 | } |
355 | ||
f2edb557 JH |
356 | void MainWindow::session_error( |
357 | const QString text, const QString info_text) | |
358 | { | |
359 | QMetaObject::invokeMethod(this, "show_session_error", | |
360 | Qt::QueuedConnection, Q_ARG(QString, text), | |
361 | Q_ARG(QString, info_text)); | |
362 | } | |
363 | ||
d873f4d6 | 364 | void MainWindow::update_device_list() |
107ca6d3 JH |
365 | { |
366 | assert(_sampling_bar); | |
367 | ||
d873f4d6 | 368 | shared_ptr<pv::device::DevInst> selected_device = _session.get_device(); |
85843b14 | 369 | list< shared_ptr<device::DevInst> > devices; |
52a80eb3 SA |
370 | |
371 | if (_device_manager.devices().size() == 0) | |
372 | return; | |
373 | ||
85843b14 JH |
374 | std::copy(_device_manager.devices().begin(), |
375 | _device_manager.devices().end(), std::back_inserter(devices)); | |
376 | ||
a5ea63c2 JH |
377 | if (std::find(devices.begin(), devices.end(), selected_device) == |
378 | devices.end()) | |
379 | devices.push_back(selected_device); | |
e95e8563 | 380 | assert(selected_device); |
a5ea63c2 | 381 | |
e95e8563 | 382 | _sampling_bar->set_device_list(devices, selected_device); |
107ca6d3 JH |
383 | } |
384 | ||
93f683ad SA |
385 | void MainWindow::closeEvent(QCloseEvent *event) |
386 | { | |
387 | save_ui_settings(); | |
388 | event->accept(); | |
389 | } | |
390 | ||
1d478458 JH |
391 | void MainWindow::load_file(QString file_name) |
392 | { | |
f2edb557 JH |
393 | const QString errorMessage( |
394 | QString("Failed to load file %1").arg(file_name)); | |
395 | const QString infoMessage; | |
ae2d1bc5 JH |
396 | |
397 | try { | |
398 | _session.set_file(file_name.toStdString()); | |
399 | } catch(QString e) { | |
400 | show_session_error(tr("Failed to load ") + file_name, e); | |
6fd0b639 JH |
401 | _session.set_default_device(); |
402 | update_device_list(); | |
403 | return; | |
ae2d1bc5 JH |
404 | } |
405 | ||
a5ea63c2 JH |
406 | update_device_list(); |
407 | ||
6db73158 JH |
408 | _session.start_capture([&, errorMessage, infoMessage](QString) { |
409 | session_error(errorMessage, infoMessage); }); | |
f2edb557 JH |
410 | } |
411 | ||
412 | void MainWindow::show_session_error( | |
413 | const QString text, const QString info_text) | |
414 | { | |
415 | QMessageBox msg(this); | |
416 | msg.setText(text); | |
417 | msg.setInformativeText(info_text); | |
418 | msg.setStandardButtons(QMessageBox::Ok); | |
419 | msg.setIcon(QMessageBox::Warning); | |
420 | msg.exec(); | |
1d478458 JH |
421 | } |
422 | ||
2953961c JH |
423 | void MainWindow::on_actionOpen_triggered() |
424 | { | |
643f65f9 JS |
425 | QSettings settings; |
426 | const QString dir = settings.value(SettingOpenDirectory).toString(); | |
427 | ||
1d43d767 | 428 | // Show the dialog |
1d478458 | 429 | const QString file_name = QFileDialog::getOpenFileName( |
643f65f9 | 430 | this, tr("Open File"), dir, tr( |
6866d5de JH |
431 | "Sigrok Sessions (*.sr);;" |
432 | "All Files (*.*)")); | |
643f65f9 JS |
433 | |
434 | if (!file_name.isEmpty()) { | |
92b139d0 | 435 | load_file(file_name); |
643f65f9 JS |
436 | |
437 | const QString abs_path = QFileInfo(file_name).absolutePath(); | |
438 | settings.setValue(SettingOpenDirectory, abs_path); | |
439 | } | |
2953961c JH |
440 | } |
441 | ||
0fbda3c2 JH |
442 | void MainWindow::on_actionSaveAs_triggered() |
443 | { | |
444 | using pv::dialogs::StoreProgress; | |
445 | ||
446 | // Stop any currently running capture session | |
447 | _session.stop_capture(); | |
448 | ||
643f65f9 JS |
449 | QSettings settings; |
450 | const QString dir = settings.value(SettingSaveDirectory).toString(); | |
451 | ||
0fbda3c2 JH |
452 | // Show the dialog |
453 | const QString file_name = QFileDialog::getSaveFileName( | |
643f65f9 | 454 | this, tr("Save File"), dir, tr("Sigrok Sessions (*.sr)")); |
0fbda3c2 JH |
455 | |
456 | if (file_name.isEmpty()) | |
457 | return; | |
458 | ||
643f65f9 JS |
459 | const QString abs_path = QFileInfo(file_name).absolutePath(); |
460 | settings.setValue(SettingSaveDirectory, abs_path); | |
461 | ||
0fbda3c2 JH |
462 | StoreProgress *dlg = new StoreProgress(file_name, _session, this); |
463 | dlg->run(); | |
464 | } | |
465 | ||
9663c82b JH |
466 | void MainWindow::on_actionConnect_triggered() |
467 | { | |
b99cfc42 JH |
468 | // Stop any currently running capture session |
469 | _session.stop_capture(); | |
470 | ||
107ca6d3 | 471 | dialogs::Connect dlg(this, _device_manager); |
5eb0fa13 | 472 | |
dc0867ff JH |
473 | // If the user selected a device, select it in the device list. Select the |
474 | // current device otherwise. | |
d873f4d6 JH |
475 | if (dlg.exec()) |
476 | _session.set_device(dlg.get_selected_device()); | |
dc0867ff | 477 | |
d873f4d6 | 478 | update_device_list(); |
9663c82b JH |
479 | } |
480 | ||
2a032dcb JH |
481 | void MainWindow::on_actionQuit_triggered() |
482 | { | |
483 | close(); | |
484 | } | |
485 | ||
a429590b JH |
486 | void MainWindow::on_actionViewZoomIn_triggered() |
487 | { | |
488 | _view->zoom(1); | |
489 | } | |
490 | ||
491 | void MainWindow::on_actionViewZoomOut_triggered() | |
492 | { | |
493 | _view->zoom(-1); | |
494 | } | |
495 | ||
ca46b534 JH |
496 | void MainWindow::on_actionViewZoomFit_triggered() |
497 | { | |
498 | _view->zoom_fit(); | |
499 | } | |
500 | ||
d1e7d82c JH |
501 | void MainWindow::on_actionViewZoomOneToOne_triggered() |
502 | { | |
503 | _view->zoom_one_to_one(); | |
504 | } | |
505 | ||
e072efc8 JH |
506 | void MainWindow::on_actionViewShowCursors_triggered() |
507 | { | |
508 | assert(_view); | |
b4d91e56 JH |
509 | |
510 | const bool show = !_view->cursors_shown(); | |
511 | if(show) | |
512 | _view->centre_cursors(); | |
513 | ||
514 | _view->show_cursors(show); | |
e072efc8 JH |
515 | } |
516 | ||
30236a54 JH |
517 | void MainWindow::on_actionAbout_triggered() |
518 | { | |
acda14b8 | 519 | dialogs::About dlg(this); |
40eb2ff4 | 520 | dlg.exec(); |
30236a54 | 521 | } |
274d4f13 | 522 | |
f0d37dab | 523 | void MainWindow::add_decoder(srd_decoder *decoder) |
7dd093df | 524 | { |
269528f5 | 525 | #ifdef ENABLE_DECODE |
f0d37dab JH |
526 | assert(decoder); |
527 | _session.add_decoder(decoder); | |
269528f5 JH |
528 | #else |
529 | (void)decoder; | |
530 | #endif | |
7dd093df JH |
531 | } |
532 | ||
274d4f13 JH |
533 | void MainWindow::run_stop() |
534 | { | |
5b7cf66c JH |
535 | switch(_session.get_capture_state()) { |
536 | case SigSession::Stopped: | |
6db73158 JH |
537 | _session.start_capture([&](QString message) { |
538 | session_error("Capture failed", message); }); | |
5b7cf66c JH |
539 | break; |
540 | ||
2b49eeb0 | 541 | case SigSession::AwaitingTrigger: |
5b7cf66c JH |
542 | case SigSession::Running: |
543 | _session.stop_capture(); | |
544 | break; | |
545 | } | |
274d4f13 | 546 | } |
51e77110 | 547 | |
6ac96c2e JH |
548 | void MainWindow::capture_state_changed(int state) |
549 | { | |
2b49eeb0 | 550 | _sampling_bar->set_capture_state((pv::SigSession::capture_state)state); |
6ac96c2e JH |
551 | } |
552 | ||
51e77110 | 553 | } // namespace pv |