fix awdw solo vicon crash, fix nested clip for binfolders, open edit edl
[goodguy/cinelerra.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 "bchash.h"
24 #include "confirmsave.h"
25 #include "language.h"
26 #include "mwindow.h"
27 #include "mwindowgui.h"
28
29
30 ConfirmSave::ConfirmSave()
31 {
32 }
33
34 ConfirmSave::~ConfirmSave()
35 {
36 }
37
38 int ConfirmSave::get_save_path(MWindow *mwindow, char *filename)
39 {
40         int result = 1;
41         char directory[BCTEXTLEN];
42         sprintf(directory, "~");
43         mwindow->defaults->get("DIRECTORY", directory);
44         while( result ) {
45                 int mx, my;  mwindow->gui->get_abs_cursor(mx, my);
46                 my -= BC_WindowBase::get_resources()->filebox_h / 2;
47                 char string[BCTEXTLEN];
48                 sprintf(string, _("Enter a filename to save as"));
49                 BC_FileBox *filebox = new BC_FileBox(mx, my, directory,
50                         _(PROGRAM_NAME ": Save"), string);
51                 filebox->lock_window("ConfirmSave::get_save_path");
52                 filebox->create_objects();
53                 filebox->unlock_window();
54                 result = filebox->run_window();
55                 mwindow->defaults->update("DIRECTORY", filebox->get_submitted_path());
56                 strcpy(filename, filebox->get_submitted_path());
57                 delete filebox;
58                 if( result == 1 ) return 1;     // user cancelled
59                 if( !filename[0] ) return 1;    // no filename given
60 // Extend the filename with .xml
61                 if( strlen(filename) < 4 ||
62                     strcasecmp(&filename[strlen(filename) - 4], ".xml") ) {
63                         strcat(filename, ".xml");
64                 }
65                 result = ConfirmSave::test_file(mwindow, filename);
66         }
67         return result;
68 }
69
70 int ConfirmSave::test_file(MWindow *mwindow, char *path)
71 {
72         ArrayList<char*> paths;
73         paths.append(path);
74         int result = test_files(mwindow, &paths);
75         paths.remove_all();
76         return result;
77 }
78
79 int ConfirmSave::test_files(MWindow *mwindow, ArrayList<char*> *paths)
80 {
81         ArrayList<BC_ListBoxItem*> list;
82         int result = 0;
83
84         for(int i = 0; i < paths->size(); i++) {
85                 char *path = paths->values[i];
86                 if( !access(path, F_OK) ) {
87                         list.append(new BC_ListBoxItem(path));
88                 }
89         }
90
91         if(list.total) {
92                 if(mwindow) {
93                         ConfirmSaveWindow window(mwindow, &list);
94                         window.create_objects();
95                         window.raise_window();
96                         result = window.run_window();
97                 }
98                 else {
99                         printf(_("The following files exist:\n"));
100                         for(int i = 0; i < list.total; i++) {
101                                 printf("    %s\n", list.values[i]->get_text());
102                         }
103                         printf(_("Won't overwrite existing files.\n"));
104                         result = 1;
105                 }
106                 list.remove_all_objects();
107                 return result;
108         }
109         else {
110                 list.remove_all_objects();
111                 return 0;
112         }
113
114         return result;
115 }
116
117
118 #define CSW_W xS(400)
119 #define CSW_H yS(150)
120
121 ConfirmSaveWindow::ConfirmSaveWindow(MWindow *mwindow,
122         ArrayList<BC_ListBoxItem*> *list)
123  : BC_Window(_(PROGRAM_NAME ": File Exists"),
124                 mwindow->gui->get_abs_cursor_x(1) - CSW_W/2,
125                 mwindow->gui->get_abs_cursor_y(1) - CSW_H/2,
126                 CSW_W, CSW_H)
127 {
128         this->list = list;
129 }
130
131 ConfirmSaveWindow::~ConfirmSaveWindow()
132 {
133 }
134
135
136 void ConfirmSaveWindow::create_objects()
137 {
138         int xs10 = xS(10);
139         int ys10 = yS(10), ys30 = yS(30);
140         int x = xs10, y = ys10;
141         lock_window("ConfirmSaveWindow::create_objects");
142         add_subwindow(new BC_OKButton(this));
143         add_subwindow(new BC_CancelButton(this));
144
145         add_subwindow(title = new BC_Title(x,
146                 y,
147                 _("The following files exist.  Overwrite them?")));
148         y += ys30;
149         add_subwindow(listbox = new BC_ListBox(x, y,
150                 get_w() - x - xs10,
151                 get_h() - y - BC_OKButton::calculate_h() - ys10,
152                 LISTBOX_TEXT,
153                 list));
154         add_subwindow(new BC_OKButton(this));
155         add_subwindow(new BC_CancelButton(this));
156         show_window(1);
157         unlock_window();
158 }
159
160 int ConfirmSaveWindow::resize_event(int w, int h)
161 {
162         int xs10 = xS(10);
163         int ys10 = yS(10), ys30 = yS(30);
164         int x = xs10, y = ys10;
165         title->reposition_window(x, y);
166         y += ys30;
167         listbox->reposition_window(x, y,
168                 w - x - xs10,
169                 h - y - BC_OKButton::calculate_h() - ys10);
170         return 1;
171 }
172