remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / cinelerra / quit.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 "assets.h"
23 #include "mbuttons.h"
24 #include "confirmquit.h"
25 #include "errorbox.h"
26 #include "language.h"
27 #include "levelwindow.h"
28 #include "levelwindowgui.h"
29 #include "mainmenu.h"
30 #include "mwindow.h"
31 #include "mwindowgui.h"
32 #include "playback3d.h"
33 #include "quit.h"
34 #include "record.h"
35 #include "render.h"
36 #include "savefile.h"
37 #include "mainsession.h"
38 #include "videowindow.h"
39 #include "videowindowgui.h"
40
41
42 Quit::Quit(MWindow *mwindow)
43  : BC_MenuItem(_("Quit"), "q", 'q'), Thread()
44 {
45         this->mwindow = mwindow;
46 }
47
48 void Quit::create_objects(Save *save)
49 {
50         this->save = save;
51 }
52
53 int Quit::handle_event()
54 {
55
56 //printf("Quit::handle_event 1 %d\n", mwindow->session->changes_made);
57         Record *record = mwindow->gui->record;
58         if( mwindow->session->changes_made || mwindow->render->in_progress ||
59                 record->capturing || record->recording || record->writing_file ) {
60                 start();
61         }
62         else
63         {        // quit
64                 mwindow->quit();
65         }
66         return 0;
67 }
68
69 void Quit::run()
70 {
71         int result = 0;
72
73 // Test execution conditions
74         Record *record = mwindow->gui->record;
75         if( record->capturing || record->recording || record->writing_file ) {
76                 ErrorBox error(_(PROGRAM_NAME ": Error"),
77                         mwindow->gui->get_abs_cursor_x(1),
78                         mwindow->gui->get_abs_cursor_y(1));
79                 error.create_objects(_("Can't quit while a recording is in progress."));
80                 error.run_window();
81                 return;
82         }
83         else
84         if(mwindow->render->thread->running())
85         {
86                 ErrorBox error(_(PROGRAM_NAME ": Error"),
87                         mwindow->gui->get_abs_cursor_x(1),
88                         mwindow->gui->get_abs_cursor_y(1));
89                 error.create_objects(_("Can't quit while a render is in progress."));
90                 error.run_window();
91                 return;
92         }
93
94         ConfirmQuitWindow confirm(mwindow);
95         confirm.create_objects(_("Save edit list before exiting?"));
96         result = confirm.run_window();
97
98         switch( result ) {
99         case 0:         // quit
100                 if( mwindow->gui )
101                         mwindow->quit();
102                 break;
103
104         case 1:         // cancel
105                 break;
106
107         case 2:         // save
108                 save->save_before_quit();
109                 break;
110         }
111 }