r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / confirmsave.C
blob027f5c7549f7fc8ec6873768a5800b8f96a07e7a
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                 240)
91         this->list = list;
94 ConfirmSaveWindow::~ConfirmSaveWindow()
99 int ConfirmSaveWindow::create_objects()
101         int x = 10, y = 10;
102         add_subwindow(title = new BC_Title(5, 
103                 5, 
104                 _("The following files exist.  Overwrite them?")));
105         y += 30;
106         add_subwindow(listbox = new BC_ListBox(x, 
107                 y, 
108                 get_w() - x - 10,
109                 get_h() - y - 50,
110                 LISTBOX_TEXT,
111                 list));
112         y = get_h() - 40;
113         add_subwindow(new BC_OKButton(this));
114         x = get_w() - 100;
115         add_subwindow(new BC_CancelButton(this));
116         return 0;
119 int ConfirmSaveWindow::resize_event(int w, int h)
121         int x = 10, y = 10;
122         title->reposition_window(x, y);
123         y += 30;
124         listbox->reposition_window(x,
125                 y,
126                 w - x - 10,
127                 h - y - 50);
128         return 1;