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