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