00001 #include "asset.h"
00002 #include "confirmsave.h"
00003 #include "language.h"
00004 #include "mwindow.h"
00005 #include "mwindowgui.h"
00006
00007
00008
00009
00010 ConfirmSave::ConfirmSave()
00011 {
00012 }
00013
00014 ConfirmSave::~ConfirmSave()
00015 {
00016 }
00017
00018 int ConfirmSave::test_file(MWindow *mwindow, char *path)
00019 {
00020 ArrayList<char*> paths;
00021 paths.append(path);
00022 int result = test_files(mwindow, &paths);
00023 paths.remove_all();
00024 return result;
00025 }
00026
00027 int ConfirmSave::test_files(MWindow *mwindow,
00028 ArrayList<char*> *paths)
00029 {
00030 FILE *file;
00031 ArrayList<BC_ListBoxItem*> list;
00032 int result = 0;
00033
00034 for(int i = 0; i < paths->total; i++)
00035 {
00036 char *path = paths->values[i];
00037 if(file = fopen(path, "r"))
00038 {
00039 fclose(file);
00040 list.append(new BC_ListBoxItem(path));
00041 }
00042 }
00043
00044 if(list.total)
00045 {
00046 if(mwindow)
00047 {
00048 ConfirmSaveWindow window(mwindow, &list);
00049 window.create_objects();
00050 window.raise_window();
00051 result = window.run_window();
00052 }
00053 else
00054 {
00055 printf("The following files exist.\n");
00056 for(int i = 0; i < list.total; i++)
00057 {
00058 printf(" %s\n", list.values[i]->get_text());
00059 }
00060 printf("It's so hard to configure non-interactive rendering that\n"
00061 "we'll assume you didn't want to overwrite them and crash here.\n");
00062 result = 1;
00063 }
00064 list.remove_all_objects();
00065 return result;
00066 }
00067 else
00068 {
00069 list.remove_all_objects();
00070 return 0;
00071 }
00072
00073 return result;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 ConfirmSaveWindow::ConfirmSaveWindow(MWindow *mwindow,
00085 ArrayList<BC_ListBoxItem*> *list)
00086 : BC_Window(PROGRAM_NAME ": File Exists",
00087 mwindow->gui->get_abs_cursor_x(1) - 160,
00088 mwindow->gui->get_abs_cursor_y(1) - 120,
00089 320,
00090 320)
00091 {
00092 this->list = list;
00093 }
00094
00095 ConfirmSaveWindow::~ConfirmSaveWindow()
00096 {
00097 }
00098
00099
00100 int ConfirmSaveWindow::create_objects()
00101 {
00102 int x = 10, y = 10;
00103 add_subwindow(new BC_OKButton(this));
00104 add_subwindow(new BC_CancelButton(this));
00105
00106 add_subwindow(title = new BC_Title(x,
00107 y,
00108 _("The following files exist. Overwrite them?")));
00109 y += 30;
00110 add_subwindow(listbox = new BC_ListBox(x,
00111 y,
00112 get_w() - x - 10,
00113 get_h() - y - BC_OKButton::calculate_h() - 10,
00114 LISTBOX_TEXT,
00115 list));
00116 y = get_h() - 40;
00117 add_subwindow(new BC_OKButton(this));
00118 x = get_w() - 100;
00119 add_subwindow(new BC_CancelButton(this));
00120 return 0;
00121 }
00122
00123 int ConfirmSaveWindow::resize_event(int w, int h)
00124 {
00125 int x = 10, y = 10;
00126 title->reposition_window(x, y);
00127 y += 30;
00128 listbox->reposition_window(x,
00129 y,
00130 w - x - 10,
00131 h - y - 50);
00132 return 1;
00133 }
00134
00135
00136
00137
00138
00139