summaryrefslogtreecommitdiffstats
path: root/src/util/util.cpp
diff options
context:
space:
mode:
authorSebastien Braun2010-10-05 22:57:48 +0200
committerSebastien Braun2010-10-05 22:57:48 +0200
commit0cb19c0a597bfb7a6cac416fb5c0b0a89043081e (patch)
tree1c076c798ae6ce960bccde2e0aea675143d961d8 /src/util/util.cpp
parentFix SIGSEGV-generating lookup bug when incoming multicast transfers are retried (diff)
parent[PVSGUI] parsing cmdargs fixed (diff)
downloadpvs-0cb19c0a597bfb7a6cac416fb5c0b0a89043081e.tar.gz
pvs-0cb19c0a597bfb7a6cac416fb5c0b0a89043081e.tar.xz
pvs-0cb19c0a597bfb7a6cac416fb5c0b0a89043081e.zip
Merge remote branch 'openslx/master' into mcastft
Conflicts: CMakeLists.txt pvsmgr.qrc src/gui/clientConfigDialog.cpp src/gui/mainWindow.cpp src/gui/ui/mainwindow.ui src/gui/ui/mainwindowtouch.ui src/pvs.cpp src/pvs.h src/pvsDaemon.cpp src/pvsgui.cpp
Diffstat (limited to 'src/util/util.cpp')
-rwxr-xr-x[-rw-r--r--]src/util/util.cpp64
1 files changed, 44 insertions, 20 deletions
diff --git a/src/util/util.cpp b/src/util/util.cpp
index 946168e..05a209f 100644..100755
--- a/src/util/util.cpp
+++ b/src/util/util.cpp
@@ -6,7 +6,11 @@
#include <cstdlib>
#include <QStringList>
#include <iostream>
-
+#include <QDir>
+#ifdef __WIN32__
+ #include <windows.h>
+ #include <Lmcons.h>
+#endif //__WIN32__
PVSServerEntry::PVSServerEntry(QString name)
{
@@ -45,7 +49,11 @@ int getRandom(int min, int max)
if (init)
{
init = false;
+ #ifndef __WIN32__
srand ( time(NULL) + getpid() );
+ #else
+ srand ( time(NULL) ); /*might be solved by another random factor*/
+ #endif
}
if (min >= max) return rand();
return rand() % (max-min+1) + min;
@@ -184,15 +192,28 @@ QString colonSplitter(QString line, bool first)
QString getUserName()
{
- struct passwd* passUser = getpwuid(getuid());
QString username;
- if (passUser)
- {
- username = QString(passUser->pw_name);
- }
+ #ifdef __WIN32__
+ WCHAR* lpszSystemInfo; // pointer to system information
+ DWORD cchBuff = 256; // size of user name
+ WCHAR tchBuffer[UNLEN + 1]; // buffer for expanded string
+
+ lpszSystemInfo = tchBuffer;
+
+ // Get and display the user name.
+ GetUserNameW(lpszSystemInfo, &cchBuff);
+
+ //Unicode string needs to be converted
+ username = QString::fromWCharArray(lpszSystemInfo);
+ #else
+ struct passwd* passUser = getpwuid(getuid());
+ if (passUser)
+ username = QString(passUser->pw_name);
+
+ #endif //#ifdef __WIN32__
if (username.isEmpty())
{
- printf("USERNAME COULDNT BE RETRIEVED!\n");
+ qDebug("USERNAME COULDNT BE RETRIEVED!");
username = QString("USERNAMEERROR");
}
return username;
@@ -202,19 +223,21 @@ QString getUserName()
QString getFullUsername()
{
QString fullname = getUserName();
- struct passwd *pd;
+ #ifndef __WIN32__
+ struct passwd *pd;
- if (NULL == (pd = getpwuid(getuid())))
- {ConsoleLog writeError("getpwuid() error.");}
- else
- {
- QString tmp = pd->pw_gecos;
- QStringList userData = tmp.split(",");
- if(userData[0].length() > 0 )
+ if (NULL == (pd = getpwuid(getuid())))
+ {ConsoleLog writeError("getpwuid() error.");}
+ else
{
- fullname = userData[0];
+ QString tmp = pd->pw_gecos;
+ QStringList userData = tmp.split(",");
+ if(userData[0].length() > 0 )
+ {
+ fullname = userData[0];
+ }
}
- }
+ #endif //__WIN32__ //might be completed some time to a full solution for WIN32
return fullname;
}
@@ -266,7 +289,8 @@ bool policyFileExists(QString fileName)
void createPolicyDir()
{
- mkdir(getPolicyDir().toUtf8().data(), 0777);
+ QDir(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)).mkdir(".pvs");
+ //assuming PolicyDir is defined like in getPolicyDir()
}
void createPolicyFiles()
@@ -299,7 +323,7 @@ QString readPassFromPassFile()
}
bool getAllowed()
{
- printf("Checking %s\n", getPolicyFilePath(QString(".allow")).toUtf8().data());
+ qDebug("Checking %s", qPrintable(getPolicyFilePath(QString(".allow"))));
TextFile file(getPolicyFilePath(".allow"));
if (file.good()) // should have been checked via exists before, but better be safe
{
@@ -314,7 +338,7 @@ bool getAllowed()
(allowed.compare(QString("TRUE")) == 0) )
return true;
}
- printf("...negative\n");
+ qDebug("...negative");
return false;
}