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