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