]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlLog.C
fix crash due to invalidated iterator
[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 >> logfile;
43         if (!lex)
44                 // Parsing of the data failed.
45                 return false;
46
47         if (logtype == "latex")
48                 type_ = LatexLog;
49         else if (logtype == "literate")
50                 type_ = LiterateLog;
51         else if (logtype == "lyx2lyx")
52                 type_ = Lyx2lyxLog;
53         else if (logtype == "vc")
54                 type_ = VCLog;
55         else
56                 return false;
57
58         logfile_ = logfile;
59         return true;
60 }
61
62
63 void ControlLog::clearParams()
64 {
65         logfile_.erase();
66 }
67
68
69 string const ControlLog::title() const
70 {
71         string t;
72         switch (type_) {
73         case LatexLog:
74                 t = _("LaTeX Log");
75                 break;
76         case LiterateLog:
77                 t = _("Literate Programming Build Log");
78                 break;
79         case Lyx2lyxLog:
80                 t = _("lyx2lyx Error Log");
81                 break;
82         case VCLog:
83                 t = _("Version Control Log");
84                 break;
85         }
86         return t;
87 }
88
89
90 void ControlLog::getContents(std::ostream & ss) const
91 {
92         std::ifstream in(logfile_.c_str());
93
94         bool success = false;
95
96         if (in) {
97                 ss << in.rdbuf();
98                 success = ss.good();
99         }
100
101         if (success)
102                 return;
103
104         switch (type_) {
105         case LatexLog:
106                 ss << _("No LaTeX log file found.");
107                 break;
108         case LiterateLog:
109                 ss << _("No literate programming build log file found.");
110                 break;
111         case Lyx2lyxLog:
112                 ss << _("No lyx2lyx error log file found.");
113                 break;
114         case VCLog:
115                 ss << _("No version control log file found.");
116                 break;
117         }
118 }
119
120 } // namespace frontend
121 } // namespace lyx