fix segv for plugin render_gui when plugin moved up/dn, opencv build fixes, opts...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / confirmsave.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "asset.h"
23 #include "confirmsave.h"
24 #include "language.h"
25 #include "mwindow.h"
26 #include "mwindowgui.h"
27
28
29
30
31 ConfirmSave::ConfirmSave()
32 {
33 }
34
35 ConfirmSave::~ConfirmSave()
36 {
37 }
38
39 int ConfirmSave::test_file(MWindow *mwindow, char *path)
40 {
41         ArrayList<char*> paths;
42         paths.append(path);
43         int result = test_files(mwindow, &paths);
44         paths.remove_all();
45         return result;
46 }
47
48 int ConfirmSave::test_files(MWindow *mwindow, ArrayList<char*> *paths)
49 {
50         ArrayList<BC_ListBoxItem*> list;
51         int result = 0;
52
53         for(int i = 0; i < paths->size(); i++) {
54                 char *path = paths->values[i];
55                 if( !access(path, F_OK) ) {
56                         list.append(new BC_ListBoxItem(path));
57                 }
58         }
59
60         if(list.total) {
61                 if(mwindow) {
62                         ConfirmSaveWindow window(mwindow, &list);
63                         window.create_objects();
64                         window.raise_window();
65                         result = window.run_window();
66                 }
67                 else {
68                         printf(_("The following files exist:\n"));
69                         for(int i = 0; i < list.total; i++) {
70                                 printf("    %s\n", list.values[i]->get_text());
71                         }
72                         printf(_("Won't overwrite existing files.\n"));
73                         result = 1;
74                 }
75                 list.remove_all_objects();
76                 return result;
77         }
78         else {
79                 list.remove_all_objects();
80                 return 0;
81         }
82
83         return result;
84 }
85
86
87 #define CSW_W xS(400)
88 #define CSW_H yS(150)
89
90 ConfirmSaveWindow::ConfirmSaveWindow(MWindow *mwindow,
91         ArrayList<BC_ListBoxItem*> *list)
92  : BC_Window(_(PROGRAM_NAME ": File Exists"),
93                 mwindow->gui->get_abs_cursor_x(1) - CSW_W/2,
94                 mwindow->gui->get_abs_cursor_y(1) - CSW_H/2,
95                 CSW_W, CSW_H)
96 {
97         this->list = list;
98 }
99
100 ConfirmSaveWindow::~ConfirmSaveWindow()
101 {
102 }
103
104
105 void ConfirmSaveWindow::create_objects()
106 {
107         int xs10 = xS(10);
108         int ys10 = yS(10), ys30 = yS(30);
109         int x = xs10, y = ys10;
110         lock_window("ConfirmSaveWindow::create_objects");
111         add_subwindow(new BC_OKButton(this));
112         add_subwindow(new BC_CancelButton(this));
113
114         add_subwindow(title = new BC_Title(x,
115                 y,
116                 _("The following files exist.  Overwrite them?")));
117         y += ys30;
118         add_subwindow(listbox = new BC_ListBox(x, y,
119                 get_w() - x - xs10,
120                 get_h() - y - BC_OKButton::calculate_h() - ys10,
121                 LISTBOX_TEXT,
122                 list));
123         add_subwindow(new BC_OKButton(this));
124         add_subwindow(new BC_CancelButton(this));
125         show_window(1);
126         unlock_window();
127 }
128
129 int ConfirmSaveWindow::resize_event(int w, int h)
130 {
131         int xs10 = xS(10);
132         int ys10 = yS(10), ys30 = yS(30);
133         int x = xs10, y = ys10;
134         title->reposition_window(x, y);
135         y += ys30;
136         listbox->reposition_window(x, y,
137                 w - x - xs10,
138                 h - y - BC_OKButton::calculate_h() - ys10);
139         return 1;
140 }
141