as_user.cpp

Thu, 06 Aug 2009 13:21:30 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 06 Aug 2009 13:21:30 +0200
changeset 15
0e0eb7c91312
parent 3
c1941114ca88
permissions
-rw-r--r--

Remove seemingly declarations unnecessary according to Qt 4.5.2 headers.

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

mercurial