Commit da6cc3cb authored by Karel Slaný's avatar Karel Slaný
Browse files

Pulled shared code changes from desktop application.

parent febfef60
......@@ -33,7 +33,13 @@
void Compat::seedRand(void)
{
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
qsrand(QDateTime::currentDateTime().toTime_t());
qsrand(
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
0xffffffff & QDateTime::currentDateTime().toSecsSinceEpoch()
#else /* < Qt-5.8 */
0xffffffff & (QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000)
#endif /* >= Qt-5.8 */
);
#endif /* < Qt-5.10.0 */
}
......
......@@ -193,7 +193,7 @@ QString SQLiteDb::fileName(void) const
}
#define queryBeginTransaction(db) \
queryOperation((db), "BEGIN DEFERRED TRANSACTION")
queryOperation((db), "BEGIN EXCLUSIVE TRANSACTION")
#define queryCommitTransaction(db) \
queryOperation((db), "COMMIT TRANSACTION")
......@@ -282,6 +282,16 @@ bool SQLiteDb::rollbackTransaction(const QString &savePointName)
}
}
void SQLiteDb::lock(void)
{
m_lock.lock();
}
void SQLiteDb::unlock(void)
{
m_lock.unlock();
}
bool SQLiteDb::dbDriverSupport(void)
{
QStringList driversList = QSqlDatabase::drivers();
......
......@@ -106,6 +106,20 @@ public:
*/
bool rollbackTransaction(const QString &savePointName = QString());
/*!
* @brief Explicitly lock the database for the current thread.
*
* @note This should be used the explicit transactions are applied.
*/
void lock(void);
/*!
* @brief Explicitly unlock the database for the current thread.
*
* @note This should be used the explicit transactions are applied.
*/
void unlock(void);
static
const QString memoryLocation; /*!< Specifies memory location. */
static
......
......@@ -151,7 +151,8 @@ QDateTime Isds::dateTimeFromStructTimeval(struct timeval *cDateTime)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
timeStamp.setSecsSinceEpoch(cDateTime->tv_sec);
#else /* < Qt-5.8 */
timeStamp.setTime_t(cDateTime->tv_sec);
/* Don't use QDateTime::setTime_t because it takes uint. */
timeStamp.setMSecsSinceEpoch(((qint64)cDateTime->tv_sec) * 1000);
#endif /* >= Qt-5.8 */
timeStamp = timeStamp.addMSecs(cDateTime->tv_usec / 1000);
}
......@@ -187,7 +188,8 @@ bool Isds::toCDateTimeCopy(struct timeval **cDateTimePtr,
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
(*cDateTimePtr)->tv_sec = dateTime.toSecsSinceEpoch();
#else /* < Qt-5.8 */
(*cDateTimePtr)->tv_sec = dateTime.toTime_t();
/* Don't use QDateTime::toTime_t() because it returns uint. */
(*cDateTimePtr)->tv_sec = dateTime.toMSecsSinceEpoch() / 1000;
#endif /* >= Qt-5.8 */
(*cDateTimePtr)->tv_usec = dateTime.time().msec() * 1000;
return true;
......@@ -272,7 +274,7 @@ qint64 Isds::string2NonNegativeLong(const QString &str, bool *ok)
bool iOk = false;
qint64 num = str.toLongLong(&iOk);
if ((!iOk) || (num < 0)) {
if (Q_UNLIKELY((!iOk) || (num < 0))) {
if (ok != Q_NULLPTR) {
*ok = false;
}
......
......@@ -31,7 +31,7 @@ qint64 Isds::variant2nonNegativeLong(const QVariant &v)
bool ok = false;
qint64 num = v.toLongLong(&ok);
if ((!ok) || (num < 0)) {
if (Q_UNLIKELY((!ok) || (num < 0))) {
return -1;
}
......@@ -260,6 +260,39 @@ QVariant Isds::dbType2StrVariant(enum Type::DbType bt)
}
}
enum Isds::Type::DmType Isds::char2DmType(QChar ch, bool *ok)
{
bool iOk = true;
enum Isds::Type::DmType type = Type::MT_UNKNOWN;
if (!ch.isNull()) {
switch (ch.toLatin1()) {
case Type::MT_A: type = Type::MT_A; break;
case Type::MT_B: type = Type::MT_B; break;
case Type::MT_C: type = Type::MT_C; break;
case Type::MT_D: type = Type::MT_D; break;
case Type::MT_E: type = Type::MT_E; break;
case Type::MT_G: type = Type::MT_G; break;
case Type::MT_I: type = Type::MT_I; break;
case Type::MT_K: type = Type::MT_K; break;
case Type::MT_O: type = Type::MT_O; break;
case Type::MT_V: type = Type::MT_V; break;
case Type::MT_X: type = Type::MT_X; break;
case Type::MT_Y: type = Type::MT_Y; break;
case Type::MT_Z: type = Type::MT_Z; break;
default:
Q_ASSERT(0);
iOk = false;
break;
}
}
if (ok != Q_NULLPTR) {
*ok = iOk;
}
return type;
}
enum Isds::Type::DbState Isds::long2DbState(long int bs, bool *ok)
{
bool iOk = true;
......
......@@ -52,6 +52,8 @@ namespace Isds {
enum Type::DbType strVariant2DbType(const QVariant &v);
QVariant dbType2StrVariant(enum Type::DbType bt);
enum Type::DmType char2DmType(QChar ch, bool *ok = Q_NULLPTR);
enum Type::DbState long2DbState(long int bs, bool *ok = Q_NULLPTR);
enum Type::DbState variant2DbState(const QVariant &v);
QVariant dbState2Variant(enum Type::DbState bs);
......
......@@ -205,6 +205,30 @@ namespace Isds {
MT_Z = 'Z'
};
/*!
* @brief Describes commercial (PDZ) payment type.
*
* @note Mentioned in pril_2/WS_ISDS_Vyhledavani_datovych_schranek.pdf
* (section 2.5)
*/
enum PdzPaymentType {
PPT_UNKNOWN = -1, /*!< Convenience value, converted from/to NULL. */
PPT_K = 'K', /* Commercial paid by contract. */
PPT_E = 'E', /* Commercial paid by credit. */
PPT_G = 'G', /* Sponsor-prepaid commercial. */
PPT_O = 'O', /* Commercial response paid by sender of initiatory. */
PPT_Z = 'Z', /* Undocumented, based on libdatovka. */
PPT_D = 'D' /* Undocumented, based on libdatovka. */
};
/*!
* Commercial message (PDZ) type. Convenience value, taken from libdatovka.
*/
enum PdzMessageType {
PMT_NORMAL = 0, /*!< Normal commercial message. */
PMT_INIT /*!< Initiatory commercial message. */
};
/*!
* @brief User types tUserType (dbTypes.xsd).
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment