]> git.lyx.org Git - lyx.git/blob - src/support/userinfo.cpp
Possibly fix this bug:
[lyx.git] / src / support / userinfo.cpp
1 /**
2  * \file userinfo.cpp
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  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/userinfo.h"
14 #include "support/environment.h"
15
16 #include <boost/assert.hpp>
17
18 #if defined (_WIN32)
19 # include "gettext.h"
20 # include <windows.h>
21 # include <lmcons.h>
22 #else
23 # include <pwd.h>
24 # ifdef HAVE_UNISTD_H
25 #  include <unistd.h>
26 # endif
27 #endif
28 #ifdef HAVE_SYS_TYPES_H
29 # include <sys/types.h>
30 #endif
31
32 using std::string;
33
34 namespace lyx {
35 namespace support {
36
37 docstring const user_name()
38 {
39         //FIXME: quick fix wrt bug #3764; only Anonymous is detected now.
40         //The code after should be used only after user approval.
41         return from_ascii("Anonymous");
42         
43         
44 #if defined (_WIN32)
45
46         char name[UNLEN + 1];
47         DWORD size = UNLEN + 1;
48         if (!GetUserName(name, &size))
49                 return _("Unknown user");
50         return from_local8bit(name);
51 #else
52         struct passwd * pw(getpwuid(geteuid()));
53         BOOST_ASSERT(pw);
54
55         string name = pw->pw_gecos;
56         if (name.empty())
57                 name = pw->pw_name;
58         return from_local8bit(name);
59 #endif
60 }
61
62
63 docstring const user_email()
64 {
65         //FIXME: quick fix wrt bug #3764; only Anonymous is detected now.
66         //The code after should be used only after user approval.
67         return docstring();
68
69         
70         string email = getEnv("EMAIL_ADDRESS");
71         if (email.empty())
72                 email = getEnv("EMAIL");
73         return from_local8bit(email);
74 }
75
76 } // namespace support
77 } // namespace lyx