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