MainWindow: Added format parameters to load_file
[pulseview.git] / pv / mainwindow.hpp
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 #ifndef PULSEVIEW_PV_MAINWINDOW_HPP
22 #define PULSEVIEW_PV_MAINWINDOW_HPP
23
24 #include <list>
25 #include <map>
26 #include <memory>
27
28 #include <glibmm/variant.h>
29
30 #include <QMainWindow>
31
32 #include "session.hpp"
33
34 struct srd_decoder;
35
36 class QVBoxLayout;
37
38 namespace sigrok {
39 class InputFormat;
40 class OutputFormat;
41 }
42
43 namespace pv {
44
45 class DeviceManager;
46
47 namespace toolbars {
48 class ContextBar;
49 class MainBar;
50 }
51
52 namespace view {
53 class View;
54 }
55
56 namespace widgets {
57 #ifdef ENABLE_DECODE
58 class DecoderMenu;
59 #endif
60 }
61
62 class MainWindow : public QMainWindow
63 {
64         Q_OBJECT
65
66 private:
67         /**
68          * Name of the setting used to remember the directory
69          * containing the last file that was opened.
70          */
71         static const char *SettingOpenDirectory;
72
73         /**
74          * Name of the setting used to remember the directory
75          * containing the last file that was saved.
76          */
77         static const char *SettingSaveDirectory;
78
79 public:
80         explicit MainWindow(DeviceManager &device_manager,
81                 const char *open_file_name = NULL,
82                 QWidget *parent = 0);
83
84         QAction* action_open() const;
85         QAction* action_save_as() const;
86         QAction* action_connect() const;
87         QAction* action_quit() const;
88         QAction* action_view_zoom_in() const;
89         QAction* action_view_zoom_out() const;
90         QAction* action_view_zoom_fit() const;
91         QAction* action_view_zoom_one_to_one() const;
92         QAction* action_view_show_cursors() const;
93         QAction* action_about() const;
94
95 #ifdef ENABLE_DECODE
96         QMenu* menu_decoder_add() const;
97 #endif
98
99         void run_stop();
100
101         void select_device(std::shared_ptr<devices::Device> device);
102
103 public Q_SLOTS:
104         void export_file(std::shared_ptr<sigrok::OutputFormat> format);
105
106 private:
107         void setup_ui();
108
109         void save_ui_settings();
110
111         void restore_ui_settings();
112
113         void session_error(const QString text, const QString info_text);
114
115         /**
116          * Updates the device list in the toolbar
117          */
118         void update_device_list();      
119
120 private:
121         void closeEvent(QCloseEvent *event);
122
123         void keyReleaseEvent(QKeyEvent *event);
124
125 private Q_SLOTS:
126         void load_file(QString file_name,
127                 std::shared_ptr<sigrok::InputFormat> format = nullptr,
128                 const std::map<std::string, Glib::VariantBase> &options =
129                         std::map<std::string, Glib::VariantBase>());
130
131         void show_session_error(
132                 const QString text, const QString info_text);
133
134         void on_actionOpen_triggered();
135         void on_actionSaveAs_triggered();
136         void on_actionQuit_triggered();
137
138         void on_actionConnect_triggered();
139
140         void on_actionViewZoomIn_triggered();
141
142         void on_actionViewZoomOut_triggered();
143
144         void on_actionViewZoomFit_triggered();
145
146         void on_actionViewZoomOneToOne_triggered();
147
148         void on_actionViewShowCursors_triggered();
149
150         void on_actionAbout_triggered();
151
152         void add_decoder(srd_decoder *decoder);
153
154         void capture_state_changed(int state);
155         void device_selected();
156
157 private:
158         DeviceManager &device_manager_;
159
160         Session session_;
161
162         pv::view::View *view_;
163
164         QWidget *central_widget_;
165         QVBoxLayout *vertical_layout_;
166
167         toolbars::MainBar *main_bar_;
168
169         QAction *const action_open_;
170         QAction *const action_save_as_;
171         QAction *const action_connect_;
172         QAction *const action_quit_;
173         QAction *const action_view_zoom_in_;
174         QAction *const action_view_zoom_out_;
175         QAction *const action_view_zoom_fit_;
176         QAction *const action_view_zoom_one_to_one_;
177         QAction *const action_view_show_cursors_;
178         QAction *const action_about_;
179
180 #ifdef ENABLE_DECODE
181         QMenu *const menu_decoders_add_;
182 #endif
183 };
184
185 } // namespace pv
186
187 #endif // PULSEVIEW_PV_MAINWINDOW_HPP