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