Add a getCurrentUser function for further reference
This commit is contained in:
parent
f09bfe37d4
commit
24952bba05
@ -1,6 +1,7 @@
|
|||||||
#include "macbackend.hpp"
|
#include "macbackend.hpp"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
std::tuple<QPoint, QPixmap> PlatformBackend::getCursor() {
|
std::tuple<QPoint, QPixmap> PlatformBackend::getCursor() {
|
||||||
#warning "TODO: Mac backend"
|
#warning "TODO: Mac backend"
|
||||||
@ -17,3 +18,16 @@ pid_t PlatformBackend::pid() {
|
|||||||
bool PlatformBackend::filenameValid(QString name) {
|
bool PlatformBackend::filenameValid(QString name) {
|
||||||
return !name.contains('/');
|
return !name.contains('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString PlatformBackend::getCurrentUser() {
|
||||||
|
auto pwent = getpwent();
|
||||||
|
if(!pwent) {
|
||||||
|
if (qEnvironmentVariableIsSet("USER"))
|
||||||
|
return QString::fromLocal8Bit(qgetenv("USER"));
|
||||||
|
else return QString();
|
||||||
|
}
|
||||||
|
QString ret = QString::fromLocal8Bit(pwent->pw_name);
|
||||||
|
endpwent();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
#define PLATFORM_CAPABILITY_PID
|
#define PLATFORM_CAPABILITY_PID
|
||||||
|
#define PLATFORM_CAPABILITY_CURRENT_USER
|
||||||
|
|
||||||
class PlatformBackend {
|
class PlatformBackend {
|
||||||
public:
|
public:
|
||||||
@ -14,6 +15,7 @@ public:
|
|||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
bool filenameValid(QString name);
|
bool filenameValid(QString name);
|
||||||
|
QString getCurrentUser();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MACBACKEND_HPP
|
#endif // MACBACKEND_HPP
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "u32backend.hpp"
|
#include "u32backend.hpp"
|
||||||
|
|
||||||
|
#include <Lmcons.h>
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
#include <QtWin>
|
#include <QtWin>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@ -43,3 +44,12 @@ bool PlatformBackend::filenameValid(QString name) {
|
|||||||
if (periods == name.length()) return false;
|
if (periods == name.length()) return false;
|
||||||
return !illegalNames.contains(name);
|
return !illegalNames.contains(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString PlatformBackend::getCurrentUser() {
|
||||||
|
char username[UNLEN + 1];
|
||||||
|
DWORD username_len = UNLEN + 1;
|
||||||
|
GetUserName(username, &username_len);
|
||||||
|
QString userName = QString::fromLocal8Bit(username, username_len);
|
||||||
|
delete[] username;
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#define PLATFORM_CAPABILITY_PID
|
#define PLATFORM_CAPABILITY_PID
|
||||||
#define PLATFORM_CAPABILITY_ACTIVEWINDOW
|
#define PLATFORM_CAPABILITY_ACTIVEWINDOW
|
||||||
#define PLATFORM_CAPABILITY_CURSOR
|
#define PLATFORM_CAPABILITY_CURSOR
|
||||||
|
#define PLATFORM_CAPABILITY_CURRENT_USER
|
||||||
|
|
||||||
class PlatformBackend {
|
class PlatformBackend {
|
||||||
public:
|
public:
|
||||||
@ -18,6 +19,7 @@ public:
|
|||||||
}
|
}
|
||||||
WId getActiveWID();
|
WId getActiveWID();
|
||||||
bool filenameValid(QString name);
|
bool filenameValid(QString name);
|
||||||
|
QString getCurrentUser();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // U32BACKEND_HPP
|
#endif // U32BACKEND_HPP
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QX11Info>
|
#include <QX11Info>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <xcb/xcb_cursor.h>
|
#include <xcb/xcb_cursor.h>
|
||||||
#include <xcb/xcb_util.h>
|
#include <xcb/xcb_util.h>
|
||||||
#include <xcb/xfixes.h>
|
#include <xcb/xfixes.h>
|
||||||
@ -28,7 +29,6 @@ pid_t PlatformBackend::pid() {
|
|||||||
return getpid();
|
return getpid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WId PlatformBackend::getActiveWID() {
|
WId PlatformBackend::getActiveWID() {
|
||||||
xcb_connection_t *connection = QX11Info::connection();
|
xcb_connection_t *connection = QX11Info::connection();
|
||||||
xcb_get_input_focus_reply_t *focusReply;
|
xcb_get_input_focus_reply_t *focusReply;
|
||||||
@ -58,3 +58,15 @@ WId PlatformBackend::getActiveWID() {
|
|||||||
bool PlatformBackend::filenameValid(QString name) {
|
bool PlatformBackend::filenameValid(QString name) {
|
||||||
return !name.contains('/');
|
return !name.contains('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString PlatformBackend::getCurrentUser() {
|
||||||
|
auto pwent = getpwent();
|
||||||
|
if(!pwent) {
|
||||||
|
if (qEnvironmentVariableIsSet("USER"))
|
||||||
|
return QString::fromLocal8Bit(qgetenv("USER"));
|
||||||
|
else return QString();
|
||||||
|
}
|
||||||
|
QString ret = QString::fromLocal8Bit(pwent->pw_name);
|
||||||
|
endpwent();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#define PLATFORM_CAPABILITY_PID
|
#define PLATFORM_CAPABILITY_PID
|
||||||
#define PLATFORM_CAPABILITY_ACTIVEWINDOW
|
#define PLATFORM_CAPABILITY_ACTIVEWINDOW
|
||||||
#define PLATFORM_CAPABILITY_CURSOR
|
#define PLATFORM_CAPABILITY_CURSOR
|
||||||
|
#define PLATFORM_CAPABILITY_CURRENT_USER
|
||||||
|
|
||||||
class PlatformBackend {
|
class PlatformBackend {
|
||||||
public:
|
public:
|
||||||
@ -17,6 +18,7 @@ public:
|
|||||||
}
|
}
|
||||||
WId getActiveWID();
|
WId getActiveWID();
|
||||||
bool filenameValid(QString name);
|
bool filenameValid(QString name);
|
||||||
|
QString getCurrentUser();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // X11BACKEND_HPP
|
#endif // X11BACKEND_HPP
|
||||||
|
Loading…
Reference in New Issue
Block a user