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