|
1 // |
|
2 // OSSP asgui - Accounting system graphical user interface |
|
3 // Copyright (c) 2002-2004 The OSSP Project (http://www.ossp.org/) |
|
4 // Copyright (c) 2002-2004 Ralf S. Engelschall <rse@engelschall.com> |
|
5 // Copyright (c) 2002-2004 Michael Schloh von Bennewitz <michael@schloh.com> |
|
6 // Copyright (c) 2002-2004 Cable & Wireless Telecommunications Services GmbH |
|
7 // |
|
8 // This file is part of OSSP asgui, an accounting system graphical user |
|
9 // interface which can be found at http://www.ossp.org/pkg/tool/asgui/. |
|
10 // |
|
11 // Permission to use, copy, modify, and distribute this software for |
|
12 // any purpose with or without fee is hereby granted, provided that |
|
13 // the above copyright notice and this permission notice appear in all |
|
14 // copies. |
|
15 // |
|
16 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
|
17 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
18 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
19 // IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR |
|
20 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
25 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
|
26 // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
27 // SUCH DAMAGE. |
|
28 // |
|
29 // as_user.cpp: ISO C++ implementation |
|
30 // |
|
31 |
|
32 // For username research |
|
33 #if defined(Q_OS_WIN32) |
|
34 #include <lmcons.h> |
|
35 #else |
|
36 #include <pwd.h> |
|
37 #include <unistd.h> |
|
38 #endif // #if defined(Q_OS_WIN32) |
|
39 |
|
40 // Local class definitions |
|
41 #include "as_user.h" |
|
42 #include "as_const.h" |
|
43 |
|
44 |
|
45 // Constructor |
|
46 User::User(void) |
|
47 { |
|
48 // Start the show by getting the username |
|
49 #if defined(Q_OS_WIN32) |
|
50 { |
|
51 DWORD dwWinusernamesize = sizeof(dwWinusernamesize); |
|
52 #if defined(UNICODE) |
|
53 TCHAR szWinusername[UNLEN + 1]; // UNLEN is defined in lmcons.h |
|
54 GetUserName(szWinusername, &dwWinusernamesize); |
|
55 m_Name = qt_winQString(szWinusername); |
|
56 #else // Not unicode |
|
57 char szWinusername[UNLEN + 1]; // UNLEN is defined in lmcons.h |
|
58 GetUserNameA(szWinusername, &dwWinusernamesize); |
|
59 this->setName(szWinusername); |
|
60 } |
|
61 #endif // #if defined(UNICODE) |
|
62 #else // Not windows |
|
63 { |
|
64 //#include <stdio.h> |
|
65 // char *szUser = NULL; |
|
66 // szUser = cuserid(); |
|
67 // m_Name = QString::fromLocal8Bit(szUser); |
|
68 |
|
69 // Get the user name from the environment |
|
70 char *szLogin = getenv(TITRAQ_ENVUSERNAME); |
|
71 if (szLogin == NULL) // Is the user name in the environment? |
|
72 szLogin = getlogin(); // No, so fetch it from the system |
|
73 |
|
74 // Get the home directory from the environment |
|
75 char *szHomedir = getenv(TITRAQ_ENVHOMEDIR); |
|
76 if (szHomedir == NULL) { // Is the home directory in the environment? |
|
77 passwd *pUserpwd = getpwnam(szLogin); // No, so fetch it from the system |
|
78 szHomedir = pUserpwd->pw_dir; // Drill into the password struct |
|
79 } |
|
80 |
|
81 this->setName(szLogin); |
|
82 this->setHomedir(szHomedir); |
|
83 } |
|
84 #endif // #if defined(Q_OS_WIN32) |
|
85 } |