]> git.lyx.org Git - lyx.git/blob - src/frontends/Alert.C
include sys/time.h
[lyx.git] / src / frontends / Alert.C
1 /**
2  * \file Alert.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #include "Alert.h"
14
15 #include "debug.h"
16 #include "lyxrc.h"
17
18 #include "Alert_pimpl.h"
19
20 #include <cerrno>
21
22 #ifndef CXX_GLOBAL_CSTD
23 using std::strerror;
24 #endif
25
26 using std::endl;
27 using std::pair;
28 using std::make_pair;
29
30
31 void Alert::alert(string const & s1, string const & s2, string const & s3)
32 {
33         if (!lyxrc.use_gui) {
34                 lyxerr << "------------------------------" << endl
35                        << s1 << endl << s2 << endl << s3 << endl
36                        << "------------------------------" << endl;
37         } else {
38                 alert_pimpl(s1, s2, s3);
39         }
40 }
41
42
43 void Alert::err_alert(string const & s1, string const & s2)
44 {
45         alert(s1, s2, strerror(errno));
46 }
47
48
49 bool Alert::askQuestion(string const & s1, string const & s2,
50                         string const & s3, bool default_value)
51 {
52         if (!lyxrc.use_gui) {
53                 lyxerr << "----------------------------------------" << endl
54                        << s1 << endl;
55                 if (!s2.empty())
56                         lyxerr << s2 << endl;
57                 if (!s3.empty())
58                         lyxerr << s3 << endl;
59                 lyxerr << "Assuming answer is "
60                        << (default_value ? "yes" : "no")
61                        << endl
62                        << "----------------------------------------" << endl;
63                 return default_value;
64         } else {
65                 return askQuestion_pimpl(s1, s2, s3);
66         }
67 }
68
69
70 int Alert::askConfirmation(string const & s1, string const & s2,
71                            string const & s3, int default_value)
72 {
73         if (!lyxrc.use_gui) {
74                 lyxerr << "----------------------------------------" << endl
75                        << s1 << endl;
76                 if (!s2.empty())
77                         lyxerr << s2 << endl;
78                 if (!s3.empty())
79                         lyxerr << s3 << endl;
80                 lyxerr << "Assuming answer is ";
81                 if (default_value == 1)
82                         lyxerr << "yes";
83                 else if (default_value == 2)
84                         lyxerr << "no";
85                 else
86                         lyxerr << "cancel";
87                 lyxerr << endl
88                        << "----------------------------------------" << endl;
89                 return default_value;
90         } else {
91                 return askConfirmation_pimpl(s1, s2, s3);
92         }
93 }
94
95
96 pair<bool, string> const Alert::askForText(string const & msg,
97                                            string const & dflt)
98 {
99         if (!lyxrc.use_gui) {
100                 lyxerr << "----------------------------------------" << endl
101                        << msg << endl
102                        << "Assuming answer is " << dflt
103                        << "----------------------------------------" << endl;
104                 return make_pair<bool, string>(true, dflt);
105         } else {
106                 return askForText_pimpl(msg, dflt);
107         }
108 }