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