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