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