r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / cinelerra / confirmsave.C
blob2327b6bdc8f0796486b031c44d8031de23dd4bc1
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                         window.raise_window();
51                         result = window.run_window();
52                 }
53                 else
54                 {
55                         printf("The following files exist.\n");
56                         for(int i = 0; i < list.total; i++)
57                         {
58                                 printf("    %s\n", list.values[i]->get_text());
59                         }
60                         printf("It's so hard to configure non-interactive rendering that\n"
61                                 "we'll assume you didn't want to overwrite them and crash here.\n");
62                         result = 1;
63                 }
64                 list.remove_all_objects();
65                 return result;
66         }
67         else
68         {
69                 list.remove_all_objects();
70                 return 0;
71         }
73         return result;
84 ConfirmSaveWindow::ConfirmSaveWindow(MWindow *mwindow, 
85         ArrayList<BC_ListBoxItem*> *list)
86  : BC_Window(PROGRAM_NAME ": File Exists", 
87                 mwindow->gui->get_abs_cursor_x(1) - 160, 
88                 mwindow->gui->get_abs_cursor_y(1) - 120, 
89                 320, 
90                 320)
92         this->list = list;
95 ConfirmSaveWindow::~ConfirmSaveWindow()
100 int ConfirmSaveWindow::create_objects()
102         int x = 10, y = 10;
103         add_subwindow(new BC_OKButton(this));
104         add_subwindow(new BC_CancelButton(this));
106         add_subwindow(title = new BC_Title(x, 
107                 y, 
108                 _("The following files exist.  Overwrite them?")));
109         y += 30;
110         add_subwindow(listbox = new BC_ListBox(x, 
111                 y, 
112                 get_w() - x - 10,
113                 get_h() - y - BC_OKButton::calculate_h() - 10,
114                 LISTBOX_TEXT,
115                 list));
116         y = get_h() - 40;
117         add_subwindow(new BC_OKButton(this));
118         x = get_w() - 100;
119         add_subwindow(new BC_CancelButton(this));
120         return 0;
123 int ConfirmSaveWindow::resize_event(int w, int h)
125         int x = 10, y = 10;
126         title->reposition_window(x, y);
127         y += 30;
128         listbox->reposition_window(x,
129                 y,
130                 w - x - 10,
131                 h - y - 50);
132         return 1;