Skip to content

Commit

Permalink
QSystemSemaphore: Fix broken translated messages
Browse files Browse the repository at this point in the history
Add Q_DECLARE_TR_FUNCTIONS() and use tr().

Pick-to: 6.1
Change-Id: I31a27afa06ee2a592a7e588283e5ff08b5d14f3b
Reviewed-by: Oswald Buddenhagen <[email protected]>
  • Loading branch information
FriedemannKleint committed Feb 24, 2021
1 parent 3be3848 commit 1128e0b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/corelib/kernel/qsystemsemaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#ifndef QSYSTEMSEMAPHORE_H
#define QSYSTEMSEMAPHORE_H

#include <QtCore/qcoreapplication.h>
#include <QtCore/qstring.h>
#include <QtCore/qscopedpointer.h>

Expand All @@ -52,7 +53,7 @@ class QSystemSemaphorePrivate;

class Q_CORE_EXPORT QSystemSemaphore
{

Q_DECLARE_TR_FUNCTIONS(QSystemSemaphore)
public:
enum AccessMode
{
Expand Down
1 change: 1 addition & 0 deletions src/corelib/kernel/qsystemsemaphore_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

#ifndef QT_NO_SYSTEMSEMAPHORE

#include "qcoreapplication.h"
#include "qsharedmemory_p.h"
#include <sys/types.h>
#ifdef QT_POSIX_IPC
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/kernel/qsystemsemaphore_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode)
return true; // we already have a semaphore

if (fileName.isEmpty()) {
errorString = QCoreApplication::translate("%1: key is empty", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle"));
errorString = QSystemSemaphore::tr("%1: key is empty").arg(QLatin1String("QSystemSemaphore::handle"));
error = QSystemSemaphore::KeyError;
return false;
}
Expand Down
27 changes: 6 additions & 21 deletions src/corelib/kernel/qsystemsemaphore_systemv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,8 @@ QT_BEGIN_NAMESPACE
key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode)
{
if (key.isEmpty()){
errorString =
#if QT_CONFIG(translation)
QCoreApplication::tr("%1: key is empty", "QSystemSemaphore")
#else
QLatin1String("%1: key is empty")
#endif
.arg(QLatin1String("QSystemSemaphore::handle:"));
errorString = QSystemSemaphore::tr("%1: key is empty")
.arg(QLatin1String("QSystemSemaphore::handle:"));
error = QSystemSemaphore::KeyError;
return -1;
}
Expand All @@ -90,13 +85,8 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode)
// Create the file needed for ftok
int built = QSharedMemoryPrivate::createUnixKeyFile(fileName);
if (-1 == built) {
errorString =
#if QT_CONFIG(translation)
QCoreApplication::tr("%1: unable to make key", "QSystemSemaphore")
#else
QLatin1String("%1: unable to make key")
#endif
.arg(QLatin1String("QSystemSemaphore::handle:"));
errorString = QSystemSemaphore::tr("%1: unable to make key")
.arg(QLatin1String("QSystemSemaphore::handle:"));
error = QSystemSemaphore::KeyError;
return -1;
}
Expand All @@ -107,13 +97,8 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode)
unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q');
#endif
if (-1 == unix_key) {
errorString =
#if QT_CONFIG(translation)
QCoreApplication::tr("%1: ftok failed", "QSystemSemaphore")
#else
QLatin1String("%1: ftok failed")
#endif
.arg(QLatin1String("QSystemSemaphore::handle:"));
errorString = QSystemSemaphore::tr("%1: ftok failed")
.arg(QLatin1String("QSystemSemaphore::handle:"));
error = QSystemSemaphore::KeyError;
return -1;
}
Expand Down
10 changes: 5 additions & 5 deletions src/corelib/kernel/qsystemsemaphore_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,24 @@ void QSystemSemaphorePrivate::setErrorString(const QString &function)
switch (errno) {
case EPERM:
case EACCES:
errorString = QCoreApplication::translate("QSystemSemaphore", "%1: permission denied").arg(function);
errorString = QSystemSemaphore::tr("%1: permission denied").arg(function);
error = QSystemSemaphore::PermissionDenied;
break;
case EEXIST:
errorString = QCoreApplication::translate("QSystemSemaphore", "%1: already exists").arg(function);
errorString = QSystemSemaphore::tr("%1: already exists").arg(function);
error = QSystemSemaphore::AlreadyExists;
break;
case ENOENT:
errorString = QCoreApplication::translate("QSystemSemaphore", "%1: does not exist").arg(function);
errorString = QSystemSemaphore::tr("%1: does not exist").arg(function);
error = QSystemSemaphore::NotFound;
break;
case ERANGE:
case ENOSPC:
errorString = QCoreApplication::translate("QSystemSemaphore", "%1: out of resources").arg(function);
errorString = QSystemSemaphore::tr("%1: out of resources").arg(function);
error = QSystemSemaphore::OutOfResources;
break;
default:
errorString = QCoreApplication::translate("QSystemSemaphore", "%1: unknown error %2").arg(function).arg(errno);
errorString = QSystemSemaphore::tr("%1: unknown error %2").arg(function).arg(errno);
error = QSystemSemaphore::UnknownError;
#if defined QSYSTEMSEMAPHORE_DEBUG
qDebug() << errorString << "key" << key << "errno" << errno << EINVAL;
Expand Down

0 comments on commit 1128e0b

Please sign in to comment.