d4caa842fdfefd516ce90af3ee0e8b20aaa1a045
[goodguy/history.git] / cinelerra-5.0 / cinelerra / dbwindow.h
1 #ifndef _DBWINDOW_H_
2 #define _DBWINDOW_H_
3
4 #include "canvas.h"
5 #include "condition.h"
6 #include "garbage.h"
7 #include "linklist.h"
8 #include "mutex.h"
9 #include "commercials.inc"
10 #include "dbwindow.inc"
11 #include "guicast.h"
12 #include "mediadb.h"
13 #include "mwindow.inc"
14
15
16 enum {
17         col_ticon, col_id, col_length, col_source,
18         col_title, col_start_time, col_access_time,
19         col_access_count, sizeof_col
20 };
21
22 class DbWindow : public Thread
23 {
24 public:
25         MWindow *mwindow;
26         DbWindowGUI *gui;
27         Mutex *window_lock;
28         Mutex *db_lock;
29         class MDb : public Garbage, public MediaDb {
30                 DbWindow *dwin;
31         public:
32                 int attach_rd() { dwin->db_lock->lock();  attachDb(0);  return 0; }
33                 int attach_wr() { dwin->db_lock->lock();  attachDb(1);  return 0; }
34                 int detach() {  dwin->db_lock->unlock();  detachDb();   return 0; }
35
36                 MDb(DbWindow *d);
37                 ~MDb();
38         } *mdb;
39
40         void start();
41         void stop();
42         void run();
43
44         DbWindow(MWindow *mwindow);
45         ~DbWindow();
46 };
47
48 class DbWindowGUI : public BC_Window
49 {
50 public:
51         DbWindow *dwindow;
52
53         DbWindowText *search_text;
54         DbWindowTitleText *title_text;
55         DbWindowInfoText *info_text;
56         DbWindowMatchCase *match_case;
57         DbWindowStart *search_start;
58         DbWindowDeleteItems *del_items;
59         DbWindowCancel *cancel;
60         DbWindowList *search_list;
61         DbWindowCanvas *canvas;
62         DbWindowTIconThread *ticon_thread;
63
64         int title_text_enable;
65         int info_text_enable;
66         int match_case_enable;
67
68         int search_x, search_y, text_x, text_y;
69         int del_items_x, del_items_y;
70         int cancel_x, cancel_y, cancel_w, cancel_h;
71         int canvas_x, canvas_y, canvas_w, canvas_h;
72         int list_x, list_y, list_w, list_h;
73         int sort_column, sort_order;
74
75         const char *search_column_titles[sizeof_col];
76         int search_column_widths[sizeof_col];
77         int search_columns[sizeof_col];
78         ArrayList<BC_ListBoxItem*> search_items[sizeof_col];
79         ArrayList<DbWindowItem*> search_results;
80
81         void create_objects();
82         void search(int n, const char *text);
83         void delete_items();
84         int close_event();
85         int resize_event(int x, int y);
86         int stop_drawing(int locked=0);
87         int start_drawing(int update=0);
88         void update();
89         static int cmpr_id_dn(const void *a, const void *b);
90         static int cmpr_id_up(const void *a, const void *b);
91         static int cmpr_length_dn(const void *a, const void *b);
92         static int cmpr_length_up(const void *a, const void *b);
93         static int cmpr_source_dn(const void *a, const void *b);
94         static int cmpr_source_up(const void *a, const void *b);
95         static int cmpr_Source_dn(const void *a, const void *b);
96         static int cmpr_Source_up(const void *a, const void *b);
97         static int cmpr_Title_dn(const void *a, const void *b);
98         static int cmpr_Title_up(const void *a, const void *b);
99         static int cmpr_title_dn(const void *a, const void *b);
100         static int cmpr_title_up(const void *a, const void *b);
101         static int cmpr_start_time_dn(const void *a, const void *b);
102         static int cmpr_start_time_up(const void *a, const void *b);
103         static int cmpr_access_time_dn(const void *a, const void *b);
104         static int cmpr_access_time_up(const void *a, const void *b);
105         static int cmpr_access_count_dn(const void *a, const void *b);
106         static int cmpr_access_count_up(const void *a, const void *b);
107         void sort_events(int column, int order);
108         void move_column(int src, int dst);
109
110         DbWindowGUI(DbWindow *dwindow);
111         ~DbWindowGUI();
112 private:
113         int search_string(const char *text, const char *sp);
114         void search_clips(MediaDb *mdb, int n, const char *text);
115         int delete_selection(MediaDb *mdb);
116 };
117
118 class DbWindowInfoText : public BC_CheckBox
119 {
120 public:
121         DbWindowGUI *gui;
122
123         int handle_event();
124         void update(int v) { set_value(gui->info_text_enable = v); }
125
126         DbWindowInfoText(DbWindowGUI *gui, int x, int y);
127         ~DbWindowInfoText();
128 };
129
130 class DbWindowTitleText : public BC_CheckBox
131 {
132 public:
133         DbWindowGUI *gui;
134
135         int handle_event();
136         void update(int v) { set_value(gui->title_text_enable = v); }
137
138         DbWindowTitleText(DbWindowGUI *gui, int x, int y);
139         ~DbWindowTitleText();
140 };
141
142 class DbWindowMatchCase : public BC_CheckBox
143 {
144 public:
145         DbWindowGUI *gui;
146
147         int handle_event();
148
149         DbWindowMatchCase(DbWindowGUI *gui, int x, int y);
150         ~DbWindowMatchCase();
151 };
152
153 class DbWindowText : public BC_TextBox
154 {
155 public:
156         DbWindowGUI *gui;
157
158         int handle_event();
159         int keypress_event();
160
161         DbWindowText(DbWindowGUI *gui, int x, int y, int w);
162         ~DbWindowText();
163 };
164
165 class DbWindowStart : public BC_GenericButton
166 {
167 public:
168         DbWindowGUI *gui;
169
170         int handle_event();
171
172         DbWindowStart(DbWindowGUI *gui, int x, int y);
173         ~DbWindowStart();
174 };
175
176 class DbWindowCancel : public BC_CancelButton
177 {
178 public:
179         DbWindowGUI *gui;
180
181         int handle_event();
182
183         DbWindowCancel(DbWindowGUI *gui, int x, int y);
184         ~DbWindowCancel();
185 };
186
187 class DbWindowDeleteItems : public BC_GenericButton
188 {
189 public:
190         DbWindowGUI *gui;
191
192         int handle_event();
193
194         DbWindowDeleteItems(DbWindowGUI *gui, int x, int y);
195         ~DbWindowDeleteItems();
196 };
197
198 class DbWindowList : public BC_ListBox
199 {
200 public:
201         DbWindowGUI *gui;
202         DbWindowTIconThread *thread;
203         BC_Popup *view_popup;
204         DbWindowTIcon *view_ticon;
205         int view_idx;
206
207         int handle_event();
208         int sort_order_event();
209         int keypress_event();
210         int move_column_event();
211         int selection_changed();
212         int stop_view_popup();
213
214         int update_images();
215         int draw_images();
216         int update();
217
218         DbWindowList(DbWindowGUI *gui, int x, int y, int w, int h);
219         ~DbWindowList();
220 };
221
222 class DbWindowCanvas : public Canvas
223 {
224 public:
225         DbWindowGUI *gui;
226         int is_fullscreen;
227
228         DbWindowCanvas(DbWindowGUI *gui, int x, int y, int w, int h);
229         ~DbWindowCanvas();
230         void flash_canvas();
231         void draw_frame(VFrame *frame, int x, int y, int w, int h);
232         int button_press_event() { return 0; }
233         int keypress_event() { return 0; }
234         int get_fullscreen() { return is_fullscreen; }
235         void set_fullscreen(int value) { is_fullscreen = value; }
236 };
237
238 class DbWindowTIcon
239 {
240 public:
241         DbWindowGUI *gui;
242         VFrame *frame;
243         double age;
244         int x, y, swidth, sheight;
245         int clip_id, clip_size;
246         int frame_id, frames, seq_no;
247         int prefix_size, suffix_offset;
248         double framerate, frame_period;
249
250         void update_image(int clip_id, int x, int y);
251         int get_seq_frame();
252         int draw_frame();
253         int draw_popup();
254         int (DbWindowTIcon::*draw)();
255         int draw_image() { return (this->*draw)(); }
256
257
258         DbWindowTIcon(DbWindowGUI *gui, int (DbWindowTIcon::*draw)());
259         ~DbWindowTIcon();
260 };
261
262 class DbWindowTIconThread : public Thread
263 {
264 public:
265         int done, interrupted;
266         int list_update, image_update;
267         DbWindowGUI *gui;
268         DbWindow::MDb *mdb;
269         Mutex *ticon_lock;
270         Timer *timer;
271         Condition *draw_lock;
272         Condition *stop_lock;
273
274         ArrayList<DbWindowTIcon *>ticons;
275         ArrayList<DbWindowTIcon *>t_heap;
276         DbWindowTIcon *get_ticon(int i);
277         DbWindowTIcon *low_ticon();
278         void add_ticon(DbWindowTIcon *ticon, double age);
279         void run();
280         void start_drawing();
281         void stop_drawing();
282
283         DbWindowTIconThread(DbWindowGUI *gui);
284         ~DbWindowTIconThread();
285 };
286
287
288 class DbWindowItem
289 {
290 public:
291         int no, id, access_count;
292         char *source, *title;
293         double length, start_time, access_time;
294
295         DbWindowItem(int id, const char *source, const char *title,
296                 double length, double start_time, double access_time,
297                 int access_count);
298         ~DbWindowItem();
299 };
300
301 class DbWindowScan : public BC_MenuItem
302 {
303 public:
304         MWindow *mwindow;
305         int handle_event();
306
307         DbWindowScan(MWindow *mwindow);
308         ~DbWindowScan();
309 };
310
311
312 #endif