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