]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlLog.C
e138e67a12027debcbb4a56b2a6c7121b62d7625
[lyx.git] / src / frontends / controllers / ControlLog.C
1 /**
2  * \file ControlLog.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  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "ControlLog.h"
15
16 #include "gettext.h"
17 #include "lyxlex.h"
18
19 #include <sstream>
20 #include <fstream>
21
22 using lyx::docstring;
23
24 using std::istringstream;
25 using std::ostream;
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31 ControlLog::ControlLog(Dialog & parent)
32         : Dialog::Controller(parent),
33           type_(LatexLog)
34 {}
35
36
37 bool ControlLog::initialiseParams(string const & data)
38 {
39         istringstream is(data);
40         LyXLex lex(0,0);
41         lex.setStream(is);
42
43         string logtype, logfile;
44         lex >> logtype;
45         if (lex.isOK()) {
46                 lex.next(true);
47                 logfile = lex.getString();
48         }
49         if (!lex)
50                 // Parsing of the data failed.
51                 return false;
52
53         if (logtype == "latex")
54                 type_ = LatexLog;
55         else if (logtype == "literate")
56                 type_ = LiterateLog;
57         else if (logtype == "lyx2lyx")
58                 type_ = Lyx2lyxLog;
59         else if (logtype == "vc")
60                 type_ = VCLog;
61         else
62                 return false;
63
64         logfile_ = logfile;
65         return true;
66 }
67
68
69 void ControlLog::clearParams()
70 {
71         logfile_.erase();
72 }
73
74
75 docstring const ControlLog::title() const
76 {
77         docstring t;
78         switch (type_) {
79         case LatexLog:
80                 t = _("LaTeX Log");
81                 break;
82         case LiterateLog:
83                 t = _("Literate Programming Build Log");
84                 break;
85         case Lyx2lyxLog:
86                 t = _("lyx2lyx Error Log");
87                 break;
88         case VCLog:
89                 t = _("Version Control Log");
90                 break;
91         }
92         return t;
93 }
94
95
96 void ControlLog::getContents(std::ostream & ss) const
97 {
98         std::ifstream in(logfile_.c_str());
99
100         bool success = false;
101
102         if (in) {
103                 ss << in.rdbuf();
104                 success = ss.good();
105         }
106
107         if (success)
108                 return;
109
110         switch (type_) {
111         case LatexLog:
112                 ss << lyx::to_utf8(_("No LaTeX log file found."));
113                 break;
114         case LiterateLog:
115                 ss << lyx::to_utf8(_("No literate programming build log file found."));
116                 break;
117         case Lyx2lyxLog:
118                 ss << lyx::to_utf8(_("No lyx2lyx error log file found."));
119                 break;
120         case VCLog:
121                 ss << lyx::to_utf8(_("No version control log file found."));
122                 break;
123         }
124 }
125
126 } // namespace frontend
127 } // namespace lyx