]> git.sesse.net Git - nageru/blob - mainwindow.h
Allow symlinked frame files. Useful for testing.
[nageru] / mainwindow.h
1 #ifndef MAINWINDOW_H
2 #define MAINWINDOW_H
3
4 #include "clip_list.h"
5 #include "db.h"
6 #include "state.pb.h"
7
8 #include <mutex>
9 #include <QLabel>
10 #include <QMainWindow>
11 #include <stdbool.h>
12 #include <sys/types.h>
13 #include <string>
14 #include <utility>
15
16 namespace Ui {
17 class MainWindow;
18 }  // namespace Ui
19
20 class Player;
21
22 class MainWindow : public QMainWindow {
23         Q_OBJECT
24
25 public:
26         MainWindow();
27
28         // HTTP callback. TODO: Does perhaps not belong to MainWindow?
29         std::pair<std::string, std::string> get_queue_status() const;
30
31 //private:
32         Ui::MainWindow *ui;
33
34 private:
35         QLabel *disk_free_label;
36         Player *preview_player, *live_player;
37         DB db;
38
39         // State when doing a scrub operation on a timestamp with the mouse.
40         bool scrubbing = false;
41         int scrub_x_origin;  // In pixels on the viewport.
42         int64_t scrub_pts_origin;
43
44         // Which element (e.g. pts_in on clip 4) we are scrubbing.
45         enum ScrubType { SCRUBBING_CLIP_LIST, SCRUBBING_PLAYLIST } scrub_type;
46         int scrub_row;
47         int scrub_column;
48
49         // Used to keep track of small mouse wheel motions on the camera index in the playlist.
50         int last_mousewheel_camera_row = -1;
51         int leftover_angle_degrees = 0;
52
53         // Some operations, notably scrubbing and scrolling, happen in so large increments
54         // that we want to group them instead of saving to disk every single time.
55         // If they happen (ie., we get a callback from the model that it's changed) while
56         // currently_deferring_model_changes, we fire off this timer. If it manages to elapse
57         // before some other event happens, we count the event. (If the other event is of the
58         // same kind, we just fire off the timer anew instead of taking any action.)
59         QTimer *defer_timeout;
60         std::string deferred_change_id;
61         StateProto deferred_state;
62
63         // Before a change that should be deferred (see above), currently_deferring_model_changes
64         // must be set to true, and current_change_id must be given contents describing what's
65         // changed to avoid accidental grouping.
66         bool currently_deferring_model_changes = false;
67         std::string current_change_id;
68
69         mutable std::mutex queue_status_mu;
70         std::string queue_status;  // Under queue_status_mu.
71
72         void cue_in_clicked();
73         void cue_out_clicked();
74         void queue_clicked();
75         void preview_clicked();
76         void preview_angle_clicked(unsigned stream_idx);
77         void play_clicked();
78         void live_player_clip_done();
79         std::pair<Clip, size_t> live_player_get_next_clip();
80         void live_player_clip_progress(const std::map<size_t, double> &progress);
81         void set_output_status(const std::string &status);
82         void playlist_duplicate();
83         void playlist_remove();
84         void playlist_move(int delta);
85
86         void defer_timer_expired();
87         void content_changed();  // In clip_list or play_list.
88         void state_changed(const StateProto &state);  // Called post-filtering.
89
90         enum Rounding { FIRST_AT_OR_AFTER, LAST_BEFORE };
91         void preview_single_frame(int64_t pts, unsigned stream_idx, Rounding rounding);
92
93         // Also covers when the playlist itself changes.
94         void playlist_selection_changed();
95
96         void clip_list_selection_changed(const QModelIndex &current, const QModelIndex &previous);
97
98         void resizeEvent(QResizeEvent *event) override;
99         bool eventFilter(QObject *watched, QEvent *event) override;
100
101         void report_disk_space(off_t free_bytes, double estimated_seconds_left);
102         void exit_triggered();
103
104         void highlight_camera_input(int stream_idx);
105
106 private slots:
107         void relayout();
108 };
109
110 extern MainWindow *global_mainwindow;
111
112 #endif