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