add bluray dv, misc fixes
[goodguy/history.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         FILE *file;
51         ArrayList<BC_ListBoxItem*> list;
52         int result = 0;
53
54         for(int i = 0; i < paths->size(); i++) {
55                 char *path = paths->values[i];
56                 if( (file=fopen(path, "r")) != 0 ) {
57                         fclose(file);
58                         list.append(new BC_ListBoxItem(path));
59                 }
60         }
61
62         if(list.total) {
63                 if(mwindow) {
64                         ConfirmSaveWindow window(mwindow, &list);
65                         window.create_objects();
66                         window.raise_window();
67                         result = window.run_window();
68                 }
69                 else {
70                         printf(_("The following files exist:\n"));
71                         for(int i = 0; i < list.total; i++) {
72                                 printf("    %s\n", list.values[i]->get_text());
73                         }
74                         printf(_("Won't overwrite existing files.\n"));
75                         result = 1;
76                 }
77                 list.remove_all_objects();
78                 return result;
79         }
80         else {
81                 list.remove_all_objects();
82                 return 0;
83         }
84
85         return result;
86 }
87
88
89
90
91
92
93
94
95
96 ConfirmSaveWindow::ConfirmSaveWindow(MWindow *mwindow,
97         ArrayList<BC_ListBoxItem*> *list)
98  : BC_Window(_(PROGRAM_NAME ": File Exists"),
99                 mwindow->gui->get_abs_cursor_x(1) - 160,
100                 mwindow->gui->get_abs_cursor_y(1) - 120,
101                 320,
102                 320)
103 {
104         this->list = list;
105 }
106
107 ConfirmSaveWindow::~ConfirmSaveWindow()
108 {
109 }
110
111
112 void ConfirmSaveWindow::create_objects()
113 {
114         int x = 10, y = 10;
115         lock_window("ConfirmSaveWindow::create_objects");
116         add_subwindow(new BC_OKButton(this));
117         add_subwindow(new BC_CancelButton(this));
118
119         add_subwindow(title = new BC_Title(x,
120                 y,
121                 _("The following files exist.  Overwrite them?")));
122         y += 30;
123         add_subwindow(listbox = new BC_ListBox(x,
124                 y,
125                 get_w() - x - 10,
126                 get_h() - y - BC_OKButton::calculate_h() - 10,
127                 LISTBOX_TEXT,
128                 list));
129         y = get_h() - 40;
130         add_subwindow(new BC_OKButton(this));
131         x = get_w() - 100;
132         add_subwindow(new BC_CancelButton(this));
133         show_window(1);
134         unlock_window();
135 }
136
137 int ConfirmSaveWindow::resize_event(int w, int h)
138 {
139         int x = 10, y = 10;
140         title->reposition_window(x, y);
141         y += 30;
142         listbox->reposition_window(x,
143                 y,
144                 w - x - 10,
145                 h - y - 50);
146         return 1;
147 }
148
149
150
151
152
153