Qt 4.8
Public Types | Public Functions | Public Variables | List of all members
QTranslatorPrivate Class Reference
Inheritance diagram for QTranslatorPrivate:
QObjectPrivate QObjectData

Public Types

enum  { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69, NumerusRules = 0x88 }
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Public Functions

void clear ()
 Empties this translator of all contents. More...
 
bool do_load (const QString &filename)
 
bool do_load (const uchar *data, int len)
 
QString do_translate (const char *context, const char *sourceText, const char *comment, int n) const
 
 QTranslatorPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

const ucharcontextArray
 
uint contextLength
 
const ucharmessageArray
 
uint messageLength
 
const ucharnumerusRulesArray
 
uint numerusRulesLength
 
const ucharoffsetArray
 
uint offsetLength
 
QResourceresource
 
unsigned int unmapLength
 
char * unmapPointer
 
bool used_mmap: 1
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 221 of file qtranslator.cpp.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
Contexts 
Hashes 
Messages 
NumerusRules 

Definition at line 225 of file qtranslator.cpp.

Constructors and Destructors

◆ QTranslatorPrivate()

QTranslatorPrivate::QTranslatorPrivate ( )
inline

Definition at line 227 of file qtranslator.cpp.

Functions

◆ clear()

void QTranslatorPrivate::clear ( )

Empties this translator of all contents.

This function works with stripped translator files.

Definition at line 968 of file qtranslator.cpp.

969 {
970  Q_Q(QTranslator);
971  if (unmapPointer && unmapLength) {
972 #if defined(QT_USE_MMAP)
973  if (used_mmap)
974  munmap(unmapPointer, unmapLength);
975  else
976 #endif
977  if (!resource)
978  delete [] unmapPointer;
979  }
980 
981  delete resource;
982  resource = 0;
983  unmapPointer = 0;
984  unmapLength = 0;
985  messageArray = 0;
986  contextArray = 0;
987  offsetArray = 0;
988  numerusRulesArray = 0;
989  messageLength = 0;
990  contextLength = 0;
991  offsetLength = 0;
992  numerusRulesLength = 0;
993 
997 }
const uchar * offsetArray
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
#define Q_Q(Class)
Definition: qglobal.h:2483
unsigned int unmapLength
QResource * resource
The QTranslator class provides internationalization support for text output.
Definition: qtranslator.h:59
const uchar * numerusRulesArray
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
static bool isTranslatorInstalled(QTranslator *translator)
const uchar * messageArray
const uchar * contextArray
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ do_load() [1/2]

bool QTranslatorPrivate::do_load ( const QString filename)

Definition at line 504 of file qtranslator.cpp.

Referenced by do_load().

505 {
506  QTranslatorPrivate *d = this;
507  bool ok = false;
508 
509  const bool isResourceFile = realname.startsWith(QLatin1Char(':'));
510  if (isResourceFile) {
511  // If the translation is in a non-compressed resource file, the data is already in
512  // memory, so no need to use QFile to copy it again.
513  Q_ASSERT(!d->resource);
514  d->resource = new QResource(realname);
515  if (d->resource->isValid() && !d->resource->isCompressed()) {
516  d->unmapLength = d->resource->size();
517  d->unmapPointer = reinterpret_cast<char *>(const_cast<uchar *>(d->resource->data()));
518  d->used_mmap = false;
519  ok = true;
520  } else {
521  delete d->resource;
522  d->resource = 0;
523  }
524  }
525 
526 #ifdef QT_USE_MMAP
527 
528 #ifndef MAP_FILE
529 #define MAP_FILE 0
530 #endif
531 #ifndef MAP_FAILED
532 #define MAP_FAILED -1
533 #endif
534 
535  else {
536  int fd = QT_OPEN(QFile::encodeName(realname), O_RDONLY,
537 #if defined(Q_OS_WIN)
539 #else
540  0666
541 #endif
542  );
543 
544  if (fd >= 0) {
545  QT_STATBUF st;
546  if (!QT_FSTAT(fd, &st)) {
547  char *ptr;
548  ptr = reinterpret_cast<char *>(
549  mmap(0, st.st_size, // any address, whole file
550  PROT_READ, // read-only memory
551  MAP_FILE | MAP_PRIVATE, // swap-backed map from file
552  fd, 0)); // from offset 0 of fd
553  if (ptr && ptr != reinterpret_cast<char *>(MAP_FAILED)) {
554  d->used_mmap = true;
555  d->unmapPointer = ptr;
556  d->unmapLength = st.st_size;
557  ok = true;
558  }
559  }
560  ::close(fd);
561  }
562  }
563 #endif // QT_USE_MMAP
564 
565  if (!ok) {
566  QFile file(realname);
567  d->unmapLength = file.size();
568  if (!d->unmapLength)
569  return false;
570  d->unmapPointer = new char[d->unmapLength];
571 
572  if (file.open(QIODevice::ReadOnly))
573  ok = (d->unmapLength == (uint)file.read(d->unmapPointer, d->unmapLength));
574 
575  if (!ok) {
576  delete [] d->unmapPointer;
577  d->unmapPointer = 0;
578  d->unmapLength = 0;
579  return false;
580  }
581  }
582 
583  return d->do_load(reinterpret_cast<const uchar *>(d->unmapPointer), d->unmapLength);
584 }
double d
Definition: qnumeric_p.h:62
#define _S_IREAD
#define O_RDONLY
bool do_load(const QString &filename)
qint64 size() const
Returns the size of the data backing the resource.
Definition: qresource.cpp:510
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define MAP_FAILED
unsigned int unmapLength
unsigned char uchar
Definition: qglobal.h:994
bool isValid() const
Returns true if the resource really exists in the resource hierarchy, false otherwise.
Definition: qresource.cpp:470
The QResource class provides an interface for reading directly from resources.
Definition: qresource.h:58
const uchar * data() const
Returns direct access to a read only segment of data that this resource represents.
Definition: qresource.cpp:526
unsigned int uint
Definition: qglobal.h:996
bool isCompressed() const
Returns true if the resource represents a file and the data backing it is in a compressed format...
Definition: qresource.cpp:497
QResource * resource
const T * ptr(const T &t)
#define QT_OPEN
Definition: qcore_unix_p.h:186
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
#define st(var, type, card)
#define Q_OS_WIN
Definition: qglobal.h:270
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
#define _S_IWRITE
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define MAP_FILE

◆ do_load() [2/2]

bool QTranslatorPrivate::do_load ( const uchar data,
int  len 
)

Definition at line 765 of file qtranslator.cpp.

766 {
767  if (!data || len < MagicLength || memcmp(data, magic, MagicLength))
768  return false;
769 
770  bool ok = true;
771  const uchar *end = data + len;
772 
773  data += MagicLength;
774 
775  while (data < end - 4) {
776  quint8 tag = read8(data++);
777  quint32 blockLen = read32(data);
778  data += 4;
779  if (!tag || !blockLen)
780  break;
781  if (data + blockLen > end) {
782  ok = false;
783  break;
784  }
785 
786  if (tag == QTranslatorPrivate::Contexts) {
787  contextArray = data;
788  contextLength = blockLen;
789  } else if (tag == QTranslatorPrivate::Hashes) {
790  offsetArray = data;
791  offsetLength = blockLen;
792  } else if (tag == QTranslatorPrivate::Messages) {
793  messageArray = data;
794  messageLength = blockLen;
795  } else if (tag == QTranslatorPrivate::NumerusRules) {
797  numerusRulesLength = blockLen;
798  }
799 
800  data += blockLen;
801  }
802 
803  return ok;
804 }
const uchar * offsetArray
unsigned char quint8
Definition: qglobal.h:934
static quint32 read32(const uchar *data)
static const int MagicLength
Definition: qtranslator.cpp:95
unsigned char uchar
Definition: qglobal.h:994
static const char * data(const QByteArray &arr)
const uchar * numerusRulesArray
unsigned int quint32
Definition: qglobal.h:938
static quint8 read8(const uchar *data)
const uchar * messageArray
const uchar * contextArray
static const KeyPair *const end
static const uchar magic[MagicLength]
Definition: qtranslator.cpp:96

◆ do_translate()

QString QTranslatorPrivate::do_translate ( const char *  context,
const char *  sourceText,
const char *  comment,
int  n 
) const

Definition at line 874 of file qtranslator.cpp.

876 {
877  if (context == 0)
878  context = "";
879  if (sourceText == 0)
880  sourceText = "";
881  if (comment == 0)
882  comment = "";
883 
884  if (!offsetLength)
885  return QString();
886 
887  /*
888  Check if the context belongs to this QTranslator. If many
889  translators are installed, this step is necessary.
890  */
891  if (contextLength) {
892  quint16 hTableSize = read16(contextArray);
893  uint g = elfHash(context) % hTableSize;
894  const uchar *c = contextArray + 2 + (g << 1);
895  quint16 off = read16(c);
896  c += 2;
897  if (off == 0)
898  return QString();
899  c = contextArray + (2 + (hTableSize << 1) + (off << 1));
900 
901  for (;;) {
902  quint8 len = read8(c++);
903  if (len == 0)
904  return QString();
905  if (match(c, context, len))
906  break;
907  c += len;
908  }
909  }
910 
911  size_t numItems = offsetLength / (2 * sizeof(quint32));
912  if (!numItems)
913  return QString();
914 
915  int numerus = 0;
916  if (n >= 0)
918 
919  for (;;) {
920  quint32 h = elfHash(QByteArray(QByteArray(sourceText) + comment).constData());
921 
922  const uchar *start = offsetArray;
923  const uchar *end = start + ((numItems-1) << 3);
924  while (start <= end) {
925  const uchar *middle = start + (((end - start) >> 4) << 3);
926  uint hash = read32(middle);
927  if (h == hash) {
928  start = middle;
929  break;
930  } else if (hash < h) {
931  start = middle + 8;
932  } else {
933  end = middle - 8;
934  }
935  }
936 
937  if (start <= end) {
938  // go back on equal key
939  while (start != offsetArray && read32(start) == read32(start-8))
940  start -= 8;
941 
942  while (start < offsetArray + offsetLength) {
943  quint32 rh = read32(start);
944  start += 4;
945  if (rh != h)
946  break;
947  quint32 ro = read32(start);
948  start += 4;
950  sourceText, comment, numerus);
951  if (!tn.isNull())
952  return tn;
953  }
954  }
955  if (!comment[0])
956  break;
957  comment = "";
958  }
959  return QString();
960 }
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
const uchar * offsetArray
unsigned char c[8]
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QString getMessage(const uchar *m, const uchar *end, const char *context, const char *sourceText, const char *comment, int numerus)
static bool match(const uchar *found, const char *target, uint len)
unsigned char quint8
Definition: qglobal.h:934
The QString class provides a Unicode character string.
Definition: qstring.h:83
static int numerusHelper(int n, const uchar *rules, int rulesSize)
static quint32 read32(const uchar *data)
unsigned char uchar
Definition: qglobal.h:994
unsigned short quint16
Definition: qglobal.h:936
unsigned int uint
Definition: qglobal.h:996
static uint elfHash(const char *name)
static quint16 read16(const uchar *data)
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
const uchar * numerusRulesArray
unsigned int quint32
Definition: qglobal.h:938
static quint8 read8(const uchar *data)
const uchar * messageArray
const uchar * contextArray
static const KeyPair *const end

Properties

◆ contextArray

const uchar* QTranslatorPrivate::contextArray

Definition at line 243 of file qtranslator.cpp.

◆ contextLength

uint QTranslatorPrivate::contextLength

Definition at line 247 of file qtranslator.cpp.

◆ messageArray

const uchar* QTranslatorPrivate::messageArray

Definition at line 241 of file qtranslator.cpp.

◆ messageLength

uint QTranslatorPrivate::messageLength

Definition at line 245 of file qtranslator.cpp.

◆ numerusRulesArray

const uchar* QTranslatorPrivate::numerusRulesArray

Definition at line 244 of file qtranslator.cpp.

◆ numerusRulesLength

uint QTranslatorPrivate::numerusRulesLength

Definition at line 248 of file qtranslator.cpp.

◆ offsetArray

const uchar* QTranslatorPrivate::offsetArray

Definition at line 242 of file qtranslator.cpp.

◆ offsetLength

uint QTranslatorPrivate::offsetLength

Definition at line 246 of file qtranslator.cpp.

◆ resource

QResource* QTranslatorPrivate::resource

Definition at line 238 of file qtranslator.cpp.

Referenced by do_load().

◆ unmapLength

unsigned int QTranslatorPrivate::unmapLength

Definition at line 235 of file qtranslator.cpp.

Referenced by do_load().

◆ unmapPointer

char* QTranslatorPrivate::unmapPointer

Definition at line 234 of file qtranslator.cpp.

Referenced by do_load().

◆ used_mmap

bool QTranslatorPrivate::used_mmap

Definition at line 233 of file qtranslator.cpp.

Referenced by do_load().


The documentation for this class was generated from the following file: