Inform the user if the current user doesn't belong to the vitamtp group.

Updated translations.
This commit is contained in:
codestation
2015-03-15 21:06:52 -04:30
parent 135f42b498
commit 1a30cee9c5
8 changed files with 213 additions and 117 deletions

View File

@@ -92,6 +92,10 @@ void HeadlessManager::start()
QSettings settings;
if(!settings.value("disableUSB", false).toBool()) {
if(!belongsToGroup("vitamtp"))
qCritical() << tr("This user doesn't belong to the vitamtp group, there could be a problem while reading the USB bus.");
usb_thread = new QThread();
client = new CmaClient(m_db);
usb_thread->setObjectName("usb_thread");

View File

@@ -36,15 +36,27 @@
#include "headlessmanager.h"
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
static void noMessageOutput(QtMsgType type, const QMessageLogContext &, const QString & str)
static void noDebugOutput(QtMsgType type, const QMessageLogContext &, const QString & msg)
{
const char * msg = str.toStdString().c_str();
QByteArray localMsg = msg.toLocal8Bit();
const char *message = localMsg.constData();
#else
static void noMessageOutput(QtMsgType type, const char *msg)
static void noDebugOutput(QtMsgType type, const char *message)
{
#endif
Q_UNUSED(type);
Q_UNUSED(msg);
switch (type) {
case QtDebugMsg:
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s\n", message);
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s\n", message);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s\n", message);
abort();
}
}
static bool setup_handlers()
@@ -102,9 +114,9 @@ int main(int argc, char *argv[])
} else {
VitaMTP_Set_Logging(VitaMTP_NONE);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
qInstallMessageHandler(noMessageOutput);
qInstallMessageHandler(noDebugOutput);
#else
qInstallMsgHandler(noMessageOutput);
qInstallMsgHandler(noDebugOutput);
#endif
}

View File

@@ -35,6 +35,13 @@
#include <sys/statvfs.h>
#endif
#ifdef Q_OS_LINUX
#include <sys/types.h>
#include <grp.h>
#include <pwd.h>
#include <unistd.h>
#endif
bool getDiskSpace(const QString &dir, quint64 *free, quint64 *total)
{
#ifdef Q_OS_WIN32
@@ -249,3 +256,50 @@ int getVitaProtocolVersion()
return protocol;
}
#ifdef Q_OS_LINUX
bool belongsToGroup(const char *groupname)
{
int size_max = sysconf(_SC_GETGR_R_SIZE_MAX);
if(size_max == -1)
size_max = 1024;
QByteArray buf(size_max, Qt::Uninitialized);
group *result = NULL;
group entry;
getgrnam_r(groupname, &entry, buf.data(), buf.size(), &result);
if(result != NULL && *result->gr_mem != NULL) {
char **user_list = result->gr_mem;
int user_size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
if(user_size_max == -1)
user_size_max = 1024;
std::vector<char> user_buf(user_size_max);
uid_t user_id = getuid();
while(*user_list != NULL) {
char *user_name = *user_list;
passwd *pw = NULL;
passwd entry;
getpwnam_r(user_name, &entry, user_buf.data(), user_buf.size(), &pw);
if(pw != NULL && pw->pw_uid == user_id) {
return true;
}
user_list++;
}
}
return false;
}
#endif

View File

@@ -51,4 +51,9 @@ bool getDiskSpace(const QString &dir, quint64 *free, quint64 *total);
QByteArray getThumbnail(const QString &path, DataType type, metadata_t *metadata);
int getVitaProtocolVersion();
#ifdef Q_OS_LINUX
bool belongsToGroup(const char *groupname);
#endif
#endif // UTILS_H

View File

@@ -95,6 +95,12 @@ void ClientManager::start()
QSettings settings;
if(!settings.value("disableUSB", false).toBool()) {
#ifdef Q_OS_LINUX
if(!belongsToGroup("vitamtp"))
emit messageSent(tr("This user doesn't belong to the vitamtp group, there could be a problem while reading the USB bus."));
#endif
usb_thread = new QThread();
client = new CmaClient(m_db);
usb_thread->setObjectName("usb_thread");