4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "confirmsave.h"
26 #include "mwindowgui.h"
31 ConfirmSave::ConfirmSave()
35 ConfirmSave::~ConfirmSave()
39 int ConfirmSave::test_file(MWindow *mwindow, char *path)
41 ArrayList<char*> paths;
43 int result = test_files(mwindow, &paths);
48 int ConfirmSave::test_files(MWindow *mwindow, ArrayList<char*> *paths)
50 ArrayList<BC_ListBoxItem*> list;
53 for(int i = 0; i < paths->size(); i++) {
54 char *path = paths->values[i];
55 if( !access(path, F_OK) ) {
56 list.append(new BC_ListBoxItem(path));
62 ConfirmSaveWindow window(mwindow, &list);
63 window.create_objects();
64 window.raise_window();
65 result = window.run_window();
68 printf(_("The following files exist:\n"));
69 for(int i = 0; i < list.total; i++) {
70 printf(" %s\n", list.values[i]->get_text());
72 printf(_("Won't overwrite existing files.\n"));
75 list.remove_all_objects();
79 list.remove_all_objects();
95 ConfirmSaveWindow::ConfirmSaveWindow(MWindow *mwindow,
96 ArrayList<BC_ListBoxItem*> *list)
97 : BC_Window(_(PROGRAM_NAME ": File Exists"),
98 mwindow->gui->get_abs_cursor_x(1) - CSW_W/2,
99 mwindow->gui->get_abs_cursor_y(1) - CSW_H/2,
105 ConfirmSaveWindow::~ConfirmSaveWindow()
110 void ConfirmSaveWindow::create_objects()
113 int ys10 = yS(10), ys30 = yS(30);
114 int x = xs10, y = ys10;
115 lock_window("ConfirmSaveWindow::create_objects");
116 add_subwindow(new BC_OKButton(this));
117 add_subwindow(new BC_CancelButton(this));
119 add_subwindow(title = new BC_Title(x,
121 _("The following files exist. Overwrite them?")));
123 add_subwindow(listbox = new BC_ListBox(x, y,
125 get_h() - y - BC_OKButton::calculate_h() - ys10,
128 add_subwindow(new BC_OKButton(this));
129 add_subwindow(new BC_CancelButton(this));
134 int ConfirmSaveWindow::resize_event(int w, int h)
137 int ys10 = yS(10), ys30 = yS(30);
138 int x = xs10, y = ys10;
139 title->reposition_window(x, y);
141 listbox->reposition_window(x, y,
143 h - y - BC_OKButton::calculate_h() - ys10);