r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / cinelerra / quit.C
blob7529ae5ccd1cf101ad7d95433c475057820b6636
1 #include "assets.h"
2 #include "mbuttons.h"
3 #include "confirmquit.h"
4 #include "errorbox.h"
5 #include "levelwindow.h"
6 #include "levelwindowgui.h"
7 #include "mainmenu.h"
8 #include "mwindow.h"
9 #include "mwindowgui.h"
10 #include "quit.h"
11 #include "record.h"
12 #include "render.h"
13 #include "savefile.h"
14 #include "mainsession.h"
15 #include "videowindow.h"
16 #include "videowindowgui.h"
18 #include <unistd.h>
19 #include <libintl.h>
20 #define _(String) gettext(String)
21 #define gettext_noop(String) String
22 #define N_(String) gettext_noop (String)
24 Quit::Quit(MWindow *mwindow)
25  : BC_MenuItem(_("Quit"), "q", 'q'), Thread() 
26
27         this->mwindow = mwindow; 
29 int Quit::create_objects(Save *save)
30
31         this->save = save; 
32         return 0;
35 int Quit::handle_event() 
38 //printf("Quit::handle_event 1 %d\n", mwindow->session->changes_made);
39         if(mwindow->session->changes_made ||
40                 mwindow->gui->mainmenu->record->current_state ||
41                 mwindow->render->running()) 
42         {
43                 start();
44         }
45         else 
46         {        // quit
47                 mwindow->gui->unlock_window();
48                 mwindow->interrupt_indexes();
49                 mwindow->gui->set_done(0);
50                 mwindow->gui->lock_window();
51         }
52         return 0;
55 void Quit::run()
57         int result = 0;
58 // Test execution conditions
59         if(mwindow->gui->mainmenu->record->current_state == RECORD_CAPTURING)
60         {
61                 ErrorBox error(PROGRAM_NAME ": Error", 
62                         mwindow->gui->get_abs_cursor_x(), 
63                         mwindow->gui->get_abs_cursor_y());
64                 error.create_objects(_("Can't quit while a recording is in progress."));
65                 error.run_window();
66                 return;
67         }
68         else
69         if(mwindow->render->running())
70         {
71                 ErrorBox error(PROGRAM_NAME ": Error", 
72                         mwindow->gui->get_abs_cursor_x(), 
73                         mwindow->gui->get_abs_cursor_y());
74                 error.create_objects(_("Can't quit while a render is in progress."));
75                 error.run_window();
76                 return;
77         }
80 //printf("Quit::run 1\n");
82 // Quit
83         {
84 //printf("Quit::run 2\n");
85                 ConfirmQuitWindow confirm(mwindow);
86 //printf("Quit::run 2\n");
87                 confirm.create_objects(_("Save edit list before exiting?"));
88 //printf("Quit::run 2\n");
89                 result = confirm.run_window();
90 //printf("Quit::run 2\n");
91         }
92 //printf("Quit::run 3\n");
94         switch(result)
95         {
96                 case 0:          // quit
97                         if(mwindow->gui)
98                         {
99                                 mwindow->interrupt_indexes();
100 // Last command in program
101                                 mwindow->gui->set_done(0);
102                         }
103                         break;
105                 case 1:        // cancel
106                         return;
107                         break;
109                 case 2:           // save
110                         save->save_before_quit(); 
111                         return;
112                         break;
113         }