r668: Configure.in and autogen.sh cleanup based on ideas by giskard.
[cinelerra_cv.git] / cinelerra / confirmsave.C
blob77ccd48336b8b1d526d76106d831d60809e4f8c8
1 #include "asset.h"
2 #include "confirmsave.h"
3 #include "language.h"
4 #include "mwindow.h"
5 #include "mwindowgui.h"
10 ConfirmSave::ConfirmSave()
14 ConfirmSave::~ConfirmSave()
18 int ConfirmSave::test_file(MWindow *mwindow, char *path)
20         ArrayList<char*> paths;
21         paths.append(path);
22         int result = test_files(mwindow, &paths);
23         paths.remove_all();
24         return result;
27 int ConfirmSave::test_files(MWindow *mwindow, 
28         ArrayList<char*> *paths)
30         FILE *file;
31         ArrayList<BC_ListBoxItem*> list;
32         int result = 0;
34         for(int i = 0; i < paths->total; i++)
35         {
36                 char *path = paths->values[i];
37                 if(file = fopen(path, "r"))
38                 {
39                         fclose(file);
40                         list.append(new BC_ListBoxItem(path));
41                 }
42         }
44         if(list.total)
45         {
46                 if(mwindow)
47                 {
48                         ConfirmSaveWindow window(mwindow, &list);
49                         window.create_objects();
50                         result = window.run_window();
51                 }
52                 else
53                 {
54                         printf("The following files exist.\n");
55                         for(int i = 0; i < list.total; i++)
56                         {
57                                 printf("    %s\n", list.values[i]->get_text());
58                         }
59                         printf("It's so hard to configure non-interactive rendering that\n"
60                                 "we'll assume you didn't want to overwrite them and crash here.\n");
61                         result = 1;
62                 }
63                 list.remove_all_objects();
64                 return result;
65         }
66         else
67         {
68                 list.remove_all_objects();
69                 return 0;
70         }
72         return result;
83 ConfirmSaveWindow::ConfirmSaveWindow(MWindow *mwindow, 
84         ArrayList<BC_ListBoxItem*> *list)
85  : BC_Window(PROGRAM_NAME ": File Exists", 
86                 mwindow->gui->get_abs_cursor_x(1) - 160, 
87                 mwindow->gui->get_abs_cursor_y(1) - 120, 
88                 320, 
89                 320)
91         this->list = list;
94 ConfirmSaveWindow::~ConfirmSaveWindow()
99 int ConfirmSaveWindow::create_objects()
101         int x = 10, y = 10;
102         add_subwindow(new BC_OKButton(this));
103         add_subwindow(new BC_CancelButton(this));
105         add_subwindow(title = new BC_Title(x, 
106                 y, 
107                 _("The following files exist.  Overwrite them?")));
108         y += 30;
109         add_subwindow(listbox = new BC_ListBox(x, 
110                 y, 
111                 get_w() - x - 10,
112                 get_h() - y - BC_OKButton::calculate_h() - 10,
113                 LISTBOX_TEXT,
114                 list));
115         y = get_h() - 40;
116         add_subwindow(new BC_OKButton(this));
117         x = get_w() - 100;
118         add_subwindow(new BC_CancelButton(this));
119         return 0;
122 int ConfirmSaveWindow::resize_event(int w, int h)
124         int x = 10, y = 10;
125         title->reposition_window(x, y);
126         y += 30;
127         listbox->reposition_window(x,
128                 y,
129                 w - x - 10,
130                 h - y - 50);
131         return 1;