r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / neworappend.C
blobd1a10f4b02172b11e96fb21298fe53a828fc919d
1 #include "assets.h"
2 #include "confirmsave.h"
3 #include "file.h"
4 #include "filesystem.h"
5 #include "keys.h"
6 #include "mwindow.h"
7 #include "mwindowgui.h"
8 #include "neworappend.h"
9 #include "theme.h"
11 #include <libintl.h>
12 #define _(String) gettext(String)
13 #define gettext_noop(String) String
14 #define N_(String) gettext_noop (String)
17 NewOrAppend::NewOrAppend(MWindow *mwindow)
19         this->mwindow = mwindow;
22 NewOrAppend::~NewOrAppend()
26 // give the user three options if the file exists
27 int NewOrAppend::test_file(Asset *asset, FileXML *script)
29         FILE *file;
30         int result = 0;
31         if(file = fopen(asset->path, "r"))
32         {
33                 fclose(file);
34                 if(!script)
35                 {
36 // Don't ask user if running a script.
37                         ConfirmSaveWindow window(mwindow, asset->path);
38                         window.create_objects();
39                         result = window.run_window();
40                 }
41                 else
42                 {
43                         result = 0;
44                 }
45                 return result;
46         }
47         else
48         {
49                 return 0;
50         }
51         
52         return 0;
60 NewOrAppendWindow::NewOrAppendWindow(MWindow *mwindow, Asset *asset, int confidence)
61  : BC_Window(PROGRAM_NAME ": Overwrite", 
62                 mwindow->gui->get_abs_cursor_x(),
63                 mwindow->gui->get_abs_cursor_y(),
64                 375, 
65                 160)
67         this->mwindow = mwindow;
68         this->asset = asset;
69         this->confidence = confidence;
72 NewOrAppendWindow::~NewOrAppendWindow()
74         delete ok;
75         delete cancel;
76         delete append;
79 int NewOrAppendWindow::create_objects()
81         char string[1024], filename[1024];
82         FileSystem fs;
83         fs.extract_name(filename, asset->path);
84         
85         sprintf(string, _("%s exists!"), filename);
86         add_subwindow(new BC_Title(5, 5, string));
87         if(confidence == 1)
88         sprintf(string, _("But is in the same format as your new file."));
89         else
90         sprintf(string, _("But might be in the same format as your new file."));
91         add_subwindow(new BC_Title(5, 25, string));
92         add_subwindow(ok = new NewOrAppendNewButton(this));
93         add_subwindow(append = new NewOrAppendAppendButton(this));
94         add_subwindow(cancel = new NewOrAppendCancelButton(this));
95         return 0;
98 NewOrAppendNewButton::NewOrAppendNewButton(NewOrAppendWindow *nwindow)
99  : BC_Button(30, 45, 0)
101         this->nwindow = nwindow;
104 int NewOrAppendNewButton::handle_event()
106         nwindow->set_done(0);
109 int NewOrAppendNewButton::keypress_event()
111         if(nwindow->get_keypress() == 13) { handle_event(); return 1; }
112         return 0;
115 NewOrAppendAppendButton::NewOrAppendAppendButton(NewOrAppendWindow *nwindow)
116  : BC_Button(30, 80, 0)
118         this->nwindow = nwindow;
121 int NewOrAppendAppendButton::handle_event()
123         nwindow->set_done(2);
126 int NewOrAppendAppendButton::keypress_event()
128         if(nwindow->get_keypress() == 13) { handle_event(); return 1; }
129         return 0;
132 NewOrAppendCancelButton::NewOrAppendCancelButton(NewOrAppendWindow *nwindow)
133  : BC_Button(30, 115, 0)
135         this->nwindow = nwindow;
138 int NewOrAppendCancelButton::handle_event()
140         nwindow->set_done(1);
143 int NewOrAppendCancelButton::keypress_event()
145         if(nwindow->get_keypress() == ESC) { handle_event(); return 1; }
146         return 0;