Formats minimally release source files based on former clang-format
This commit is contained in:
387 files changed
+37323
-38074
No files matched your search
@@ -19,9 +19,10 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
// keep in sync with log4qt/level.h
|
||||
enum class LogLevel {
|
||||
class INGLLogger;
|
||||
// keep in sync with log4qt/level.h
|
||||
enum class LogLevel
|
||||
{
|
||||
Undefined = 0,
|
||||
Trace = 64,
|
||||
Debug = 96,
|
||||
@@ -29,41 +30,44 @@ enum class LogLevel {
|
||||
Warning = 150,
|
||||
Error = 182,
|
||||
Fatal = 214,
|
||||
};
|
||||
};
|
||||
|
||||
class LogStreamHelper
|
||||
{
|
||||
class LogStreamHelper
|
||||
{
|
||||
public:
|
||||
inline LogStreamHelper(INGLLogger& logger, LogLevel level, const char* const file, int line,
|
||||
const char* const function)
|
||||
: m_logger(logger), m_level(level), m_line(line), m_file(file), m_func(function)
|
||||
inline LogStreamHelper(INGLLogger &logger, LogLevel level, const char *const file, int line, const char *const function)
|
||||
: m_logger(logger)
|
||||
, m_level(level)
|
||||
, m_line(line)
|
||||
, m_file(file)
|
||||
, m_func(function)
|
||||
{
|
||||
}
|
||||
|
||||
inline ~LogStreamHelper(); // after INGLLogger class definition
|
||||
|
||||
template <typename T> inline LogStreamHelper& operator<<(const T& val);
|
||||
template <typename T> inline LogStreamHelper &operator<<(const T &val);
|
||||
|
||||
private:
|
||||
std::ostringstream m_buffer;
|
||||
NGL::INGLLogger& m_logger;
|
||||
NGL::INGLLogger &m_logger;
|
||||
const LogLevel m_level;
|
||||
const int m_line;
|
||||
const char* const m_file;
|
||||
const char* const m_func;
|
||||
};
|
||||
const char *const m_file;
|
||||
const char *const m_func;
|
||||
};
|
||||
|
||||
// Interface class for source code logging.
|
||||
// Use NGLLoggerBootstrap to create an instance of this interface.
|
||||
// Look below in this headerfile for the macros with which to insert logging
|
||||
// code into your source code.
|
||||
// Lookup the log4cxx documentation (http://logging.apache.org/log4cxx/) for
|
||||
// information on logger-hierarchies, logging-levels, and configuration files.
|
||||
class INGLLogger
|
||||
{
|
||||
// Interface class for source code logging.
|
||||
// Use NGLLoggerBootstrap to create an instance of this interface.
|
||||
// Look below in this headerfile for the macros with which to insert logging
|
||||
// code into your source code.
|
||||
// Lookup the log4cxx documentation (http://logging.apache.org/log4cxx/) for
|
||||
// information on logger-hierarchies, logging-levels, and configuration files.
|
||||
class INGLLogger
|
||||
{
|
||||
public:
|
||||
INGLLogger(const INGLLogger&) = delete;
|
||||
INGLLogger& operator=(const INGLLogger&) = delete;
|
||||
INGLLogger(const INGLLogger &) = delete;
|
||||
INGLLogger &operator=(const INGLLogger &) = delete;
|
||||
INGLLogger() = default;
|
||||
virtual ~INGLLogger() = default;
|
||||
|
||||
@@ -73,8 +77,8 @@ class INGLLogger
|
||||
// a dottet sequence (i.e. "NGL.thisandthat.mylogger"). The same name will
|
||||
// always return the same interface-instance. It is not required to create
|
||||
// the parent nodes.
|
||||
virtual INGLLogger& getNGLLogger(const char* fullqualifiedname) = 0;
|
||||
virtual INGLLogger& getNGLLogger(const std::string& fullqualifiedname) = 0;
|
||||
virtual INGLLogger &getNGLLogger(const char *fullqualifiedname) = 0;
|
||||
virtual INGLLogger &getNGLLogger(const std::string &fullqualifiedname) = 0;
|
||||
|
||||
// True if this level is enabled.
|
||||
virtual bool isTraceEnabled() const = 0;
|
||||
@@ -87,147 +91,136 @@ class INGLLogger
|
||||
|
||||
// Submit a LOG message.
|
||||
// Use __FILE__ and __NAME__ macros.
|
||||
virtual void log(LogLevel level, const INGLLogger::String& message, const char* file = nullptr, int line = -1,
|
||||
const char* function = nullptr) = 0;
|
||||
virtual void log(LogLevel level, const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
|
||||
// Submit an TRACE message.
|
||||
virtual void logTrace(const INGLLogger::String& message, const char* file = nullptr, int line = -1,
|
||||
const char* function = nullptr) = 0;
|
||||
virtual void logTrace(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
// Submit an DEBUG message.
|
||||
virtual void logDebug(const INGLLogger::String& message, const char* file = nullptr, int line = -1,
|
||||
const char* function = nullptr) = 0;
|
||||
virtual void logDebug(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
// Submit an INFO message.
|
||||
virtual void logInfo(const INGLLogger::String& message, const char* file = nullptr, int line = -1,
|
||||
const char* function = nullptr) = 0;
|
||||
virtual void logInfo(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
// Submit a WARNING message.
|
||||
virtual void logWarning(const INGLLogger::String& message, const char* file = nullptr, int line = -1,
|
||||
const char* function = nullptr) = 0;
|
||||
virtual void logWarning(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
// Submit an ERROR message.
|
||||
virtual void logError(const INGLLogger::String& message, const char* file = nullptr, int line = -1,
|
||||
const char* function = nullptr) = 0;
|
||||
virtual void logError(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
// Submit a FATAL message.
|
||||
virtual void logFatal(const INGLLogger::String& message, const char* file = nullptr, int line = -1,
|
||||
const char* function = nullptr) = 0;
|
||||
virtual void logFatal(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
|
||||
// Writes a startup message into the logfile
|
||||
virtual void logStartup(const char* file, int line, const char* function = nullptr) = 0;
|
||||
virtual void logStartup(const char *file, int line, const char *function = nullptr) = 0;
|
||||
// Writes a shutdown message into the logfile
|
||||
virtual void logShutdown(const char* file, int line, const char* function = nullptr) = 0;
|
||||
virtual void logShutdown(const char *file, int line, const char *function = nullptr) = 0;
|
||||
|
||||
// Get this loggers fullqualified name.
|
||||
virtual std::string getLoggerName() const = 0;
|
||||
|
||||
virtual void setNoSpace(bool bNoSpace) = 0;
|
||||
virtual bool noSpace() const = 0;
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// LogStreamHelper
|
||||
//
|
||||
inline LogStreamHelper::~LogStreamHelper()
|
||||
{
|
||||
//
|
||||
// LogStreamHelper
|
||||
//
|
||||
inline LogStreamHelper::~LogStreamHelper()
|
||||
{
|
||||
m_logger.log(m_level, m_buffer.str(), m_file, m_line, m_func);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> inline LogStreamHelper& LogStreamHelper::operator<<(const T& val)
|
||||
{
|
||||
template <typename T> inline LogStreamHelper &LogStreamHelper::operator<<(const T &val)
|
||||
{
|
||||
m_buffer << val;
|
||||
if (!m_logger.noSpace())
|
||||
m_buffer << " ";
|
||||
m_buffer << " ";
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NGL
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& stream, const QByteArray& str)
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QByteArray &str)
|
||||
{
|
||||
stream << std::string(str.data(), str.size());
|
||||
return stream;
|
||||
stream << std::string(str.data(), str.size());
|
||||
return stream;
|
||||
}
|
||||
|
||||
//
|
||||
// operator to ease logging (at least via NglLogging)
|
||||
//
|
||||
inline std::ostream& operator<<(std::ostream& stream, const QPointF& value)
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QPointF &value)
|
||||
{
|
||||
stream << "QPointF(" << QString::number(value.x(), 'f', 6).toStdString() << "#"
|
||||
<< QString::number(value.y(), 'f', 6).toStdString() << ")";
|
||||
return stream;
|
||||
stream << "QPointF(" << QString::number(value.x(), 'f', 6).toStdString() << "#" << QString::number(value.y(), 'f', 6).toStdString() << ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& stream, const QPoint& value)
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QPoint &value)
|
||||
{
|
||||
stream << "QPoint(" << value.x() << "#" << value.y() << ")";
|
||||
return stream;
|
||||
stream << "QPoint(" << value.x() << "#" << value.y() << ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& stream, const QSize& value)
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QSize &value)
|
||||
{
|
||||
stream << "QSize(w=" << value.width() << ";h=" << value.height() << ")";
|
||||
return stream;
|
||||
stream << "QSize(w=" << value.width() << ";h=" << value.height() << ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& stream, const QSizeF& value)
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QSizeF &value)
|
||||
{
|
||||
stream << "QSize(w=" << QString::number(value.width(), 'f', 6).toStdString()
|
||||
<< ";h=" << QString::number(value.height(), 'f', 6).toStdString() << ")";
|
||||
return stream;
|
||||
stream << "QSize(w=" << QString::number(value.width(), 'f', 6).toStdString() << ";h=" << QString::number(value.height(), 'f', 6).toStdString() << ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& stream, const QRect& value)
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QRect &value)
|
||||
{
|
||||
stream << "QRect(center=" << value.center() << " w=" << value.width() << ";h=" << value.height()
|
||||
<< " bottomLeft=" << value.bottomLeft() << " topRight=" << value.topRight() << ")";
|
||||
return stream;
|
||||
stream << "QRect(center=" << value.center() << " w=" << value.width() << ";h=" << value.height() << " bottomLeft=" << value.bottomLeft()
|
||||
<< " topRight=" << value.topRight() << ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& stream, const QRectF& value)
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QRectF &value)
|
||||
{
|
||||
stream << "QRectF(center=" << value.center() << " w=" << QString::number(value.width(), 'f', 3).toStdString()
|
||||
<< ";h=" << QString::number(value.height(), 'f', 3).toStdString() << " bottomLeft=" << value.bottomLeft()
|
||||
<< " topRight=" << value.topRight() << ")";
|
||||
return stream;
|
||||
stream << "QRectF(center=" << value.center() << " w=" << QString::number(value.width(), 'f', 3).toStdString()
|
||||
<< ";h=" << QString::number(value.height(), 'f', 3).toStdString() << " bottomLeft=" << value.bottomLeft() << " topRight=" << value.topRight() << ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& stream, const QList<int>& value)
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QList<int> &value)
|
||||
{
|
||||
stream << "QList<int>(" << value.size() << "): ";
|
||||
for (int i : value)
|
||||
stream << i << ";";
|
||||
return stream;
|
||||
stream << "QList<int>(" << value.size() << "): ";
|
||||
for (int i : value)
|
||||
stream << i << ";";
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& stream, const QList<QPointF>& value)
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QList<QPointF> &value)
|
||||
{
|
||||
stream << "QList<QPointF>(" << value.size() << "): ";
|
||||
for (const QPointF& item : value)
|
||||
stream << item << ";";
|
||||
return stream;
|
||||
stream << "QList<QPointF>(" << value.size() << "): ";
|
||||
for (const QPointF &item : value)
|
||||
stream << item << ";";
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& stream, const QString& str)
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QString &str)
|
||||
{
|
||||
return stream << str.toUtf8();
|
||||
return stream << str.toUtf8();
|
||||
}
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
namespace NGLLoggerHelper
|
||||
{
|
||||
NGLLOGGER_EXPORT void hexDumpHelper(NGL::INGLLogger& logger, NGL::LogLevel level, const void* a_data,
|
||||
const unsigned int a_size);
|
||||
namespace NGLLoggerHelper
|
||||
{
|
||||
NGLLOGGER_EXPORT void hexDumpHelper(NGL::INGLLogger &logger, NGL::LogLevel level, const void *a_data, const unsigned int a_size);
|
||||
|
||||
inline void hexDumpHelper(NGL::INGLLogger& logger, NGL::LogLevel level, const QByteArray& data)
|
||||
{
|
||||
return hexDumpHelper(logger, level, data.data(), data.size());
|
||||
}
|
||||
} // namespace NGLLoggerHelper
|
||||
inline void hexDumpHelper(NGL::INGLLogger &logger, NGL::LogLevel level, const QByteArray &data)
|
||||
{
|
||||
return hexDumpHelper(logger, level, data.data(), data.size());
|
||||
}
|
||||
} // namespace NGLLoggerHelper
|
||||
|
||||
NGLLOGGER_EXPORT NGL::INGLLogger& getMemoryLogger();
|
||||
NGLLOGGER_EXPORT std::string getMemoryData();
|
||||
NGLLOGGER_EXPORT NGL::INGLLogger &getMemoryLogger();
|
||||
NGLLOGGER_EXPORT std::string getMemoryData();
|
||||
|
||||
} // namespace NGL
|
||||
|
||||
@@ -241,43 +234,43 @@ NGLLOGGER_EXPORT std::string getMemoryData();
|
||||
#define NOTICE_LOG(logger) NGL::LogStreamHelper(logger, NGL::LogLevel::Info, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
|
||||
#ifdef LTS_DEBUG
|
||||
#define TRACE_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isTraceEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Trace, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#define TRACE_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isTraceEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Trace, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#else
|
||||
#define TRACE_LOG(logger) \
|
||||
for (; false;) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Trace, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#define TRACE_LOG(logger) \
|
||||
for (; false;) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Trace, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#endif
|
||||
|
||||
#define DEBUG_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isDebugEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
::NGL::LogStreamHelper(logger, ::NGL::LogLevel::Debug, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#define DEBUG_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isDebugEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
::NGL::LogStreamHelper(logger, ::NGL::LogLevel::Debug, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
|
||||
#define INFO_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isInfoEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
::NGL::LogStreamHelper(logger, ::NGL::LogLevel::Info, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#define INFO_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isInfoEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
::NGL::LogStreamHelper(logger, ::NGL::LogLevel::Info, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
|
||||
#define WARNING_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isWarningEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
::NGL::LogStreamHelper(logger, ::NGL::LogLevel::Warning, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#define WARNING_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isWarningEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
::NGL::LogStreamHelper(logger, ::NGL::LogLevel::Warning, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
|
||||
#define ERROR_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isErrorEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
::NGL::LogStreamHelper(logger, ::NGL::LogLevel::Error, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#define ERROR_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isErrorEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
::NGL::LogStreamHelper(logger, ::NGL::LogLevel::Error, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
|
||||
#define FATAL_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isFatalEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
::NGL::LogStreamHelper(logger, ::NGL::LogLevel::Fatal, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#define FATAL_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isFatalEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
::NGL::LogStreamHelper(logger, ::NGL::LogLevel::Fatal, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
|
||||
#define STARTUP_LOG(logger) \
|
||||
{ \
|
||||
(logger).logStartup(__FILE__, __LINE__, Q_FUNC_INFO); \
|
||||
}
|
||||
#define SHUTDOWN_LOG(logger) \
|
||||
{ \
|
||||
(logger).logShutdown(__FILE__, __LINE__, Q_FUNC_INFO); \
|
||||
}
|
||||
#define STARTUP_LOG(logger) \
|
||||
{ \
|
||||
(logger).logStartup(__FILE__, __LINE__, Q_FUNC_INFO); \
|
||||
}
|
||||
#define SHUTDOWN_LOG(logger) \
|
||||
{ \
|
||||
(logger).logShutdown(__FILE__, __LINE__, Q_FUNC_INFO); \
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
@@ -286,10 +279,8 @@ NGLLOGGER_EXPORT std::string getMemoryData();
|
||||
// do something nasty
|
||||
// MEMORY_LOG() << " after something nasty";
|
||||
|
||||
#define MEMORY_LOG() \
|
||||
for (bool log_level_enabled = (NGL::getMemoryLogger()).isInfoEnabled(); log_level_enabled; \
|
||||
log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(NGL::getMemoryLogger(), NGL::LogLevel::Info, __FILE__, __LINE__, Q_FUNC_INFO) \
|
||||
<< NGL::getMemoryData()
|
||||
#define MEMORY_LOG() \
|
||||
for (bool log_level_enabled = (NGL::getMemoryLogger()).isInfoEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(NGL::getMemoryLogger(), NGL::LogLevel::Info, __FILE__, __LINE__, Q_FUNC_INFO) << NGL::getMemoryData()
|
||||
|
||||
//==============================================================================
|
||||
Executable → Regular
+35
-54
@@ -1,77 +1,58 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "MurmurHash2.h"
|
||||
#include <QtCore/qcompilerdetection.h>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed )
|
||||
{
|
||||
|
||||
|
||||
unsigned int MurmurHash2(const void *key, int len, unsigned int seed)
|
||||
{
|
||||
|
||||
const unsigned int m = 0x5bd1e995;
|
||||
const int r = 24;
|
||||
|
||||
|
||||
const unsigned int m = 0x5bd1e995;
|
||||
const int r = 24;
|
||||
|
||||
unsigned int h = seed ^ len;
|
||||
|
||||
|
||||
unsigned int h = seed ^ len;
|
||||
|
||||
const unsigned char * data = (const unsigned char *)key;
|
||||
|
||||
while(len >= 4)
|
||||
{
|
||||
unsigned int k = *(reinterpret_cast<const unsigned int *>(data));
|
||||
const unsigned char *data = (const unsigned char *)key;
|
||||
|
||||
k *= m;
|
||||
k ^= k >> r;
|
||||
k *= m;
|
||||
while (len >= 4)
|
||||
{
|
||||
unsigned int k = *(reinterpret_cast<const unsigned int *>(data));
|
||||
|
||||
h *= m;
|
||||
h ^= k;
|
||||
k *= m;
|
||||
k ^= k >> r;
|
||||
k *= m;
|
||||
|
||||
data += 4;
|
||||
len -= 4;
|
||||
}
|
||||
h *= m;
|
||||
h ^= k;
|
||||
|
||||
|
||||
data += 4;
|
||||
len -= 4;
|
||||
}
|
||||
|
||||
switch(len)
|
||||
{
|
||||
case 3: h ^= data[2] << 16;
|
||||
Q_FALLTHROUGH();
|
||||
case 2: h ^= data[1] << 8;
|
||||
Q_FALLTHROUGH();
|
||||
case 1: h ^= data[0];
|
||||
h *= m;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
h ^= h >> 13;
|
||||
switch (len)
|
||||
{
|
||||
case 3:
|
||||
h ^= data[2] << 16;
|
||||
Q_FALLTHROUGH();
|
||||
case 2:
|
||||
h ^= data[1] << 8;
|
||||
Q_FALLTHROUGH();
|
||||
case 1:
|
||||
h ^= data[0];
|
||||
h *= m;
|
||||
h ^= h >> 15;
|
||||
};
|
||||
|
||||
return h;
|
||||
|
||||
h ^= h >> 13;
|
||||
h *= m;
|
||||
h ^= h >> 15;
|
||||
|
||||
return h;
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable → Regular
+1
-1
@@ -5,5 +5,5 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed = 0 );
|
||||
unsigned int MurmurHash2(const void *key, int len, unsigned int seed = 0);
|
||||
}
|
||||
Executable → Regular
+144
-189
@@ -27,82 +27,73 @@
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
void LtsRollingFileAppender::setLtsLogfileName(const QString <sLogfileName)
|
||||
{
|
||||
m_ltsLogfileName = ltsLogfileName;
|
||||
}
|
||||
void LtsRollingFileAppender::setLtsLogfileName(const QString <sLogfileName)
|
||||
{
|
||||
m_ltsLogfileName = ltsLogfileName;
|
||||
}
|
||||
|
||||
void LtsRollingFileAppender::activateOptions()
|
||||
{
|
||||
if (!m_ltsLogfileName.isEmpty())
|
||||
setFile(m_ltsLogfileName);
|
||||
void LtsRollingFileAppender::activateOptions()
|
||||
{
|
||||
if (!m_ltsLogfileName.isEmpty())
|
||||
setFile(m_ltsLogfileName);
|
||||
#ifdef HAVE_LOG4QT
|
||||
Log4Qt::RollingFileAppender::activateOptions();
|
||||
Log4Qt::RollingFileAppender::activateOptions();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
QString LtsRollingFileAppender::m_ltsLogfileName;
|
||||
QString LtsRollingFileAppender::m_ltsLogfileName;
|
||||
#ifdef HAVE_LOG4QT
|
||||
static Log4Qt::Appender *createLtsRollingFileAppender()
|
||||
{
|
||||
auto ret = new LtsRollingFileAppender;
|
||||
ret->setAppendFile(true);
|
||||
return ret;
|
||||
}
|
||||
static Log4Qt::Appender *createLtsRollingFileAppender()
|
||||
{
|
||||
auto ret = new LtsRollingFileAppender;
|
||||
ret->setAppendFile(true);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
class CleanupHelper final
|
||||
{
|
||||
public:
|
||||
CleanupHelper() = default;
|
||||
~CleanupHelper();
|
||||
std::mutex &getLoggerMapMutex();
|
||||
|
||||
std::unordered_map<unsigned int, NGL::NGLLogger *> m_loggermap;
|
||||
|
||||
protected:
|
||||
std::mutex m_loggermapmutex;
|
||||
};
|
||||
|
||||
|
||||
NGL::NGLLogger *NGL::NGLLogger::rootlogger_ptr = nullptr;
|
||||
|
||||
class CleanupHelper final
|
||||
{
|
||||
public:
|
||||
CleanupHelper() = default;
|
||||
~CleanupHelper();
|
||||
std::mutex &getLoggerMapMutex();
|
||||
|
||||
std::unordered_map<unsigned int, NGL::NGLLogger *> m_loggermap;
|
||||
protected:
|
||||
std::mutex m_loggermapmutex;
|
||||
};
|
||||
NGL::CleanupHelper NGL::NGLLogger::s_cleanup;
|
||||
|
||||
|
||||
CleanupHelper::~CleanupHelper()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_loggermapmutex);
|
||||
|
||||
for (auto it : m_loggermap)
|
||||
delete it.second;
|
||||
m_loggermap.clear();
|
||||
|
||||
delete NGL::NGLLogger::rootlogger_ptr;
|
||||
NGL::NGLLogger::rootlogger_ptr = nullptr;
|
||||
}
|
||||
|
||||
NGL::NGLLogger *NGL::NGLLogger::rootlogger_ptr = nullptr;
|
||||
|
||||
NGL::CleanupHelper NGL::NGLLogger::s_cleanup;
|
||||
|
||||
|
||||
|
||||
|
||||
CleanupHelper::~CleanupHelper()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_loggermapmutex);
|
||||
|
||||
for (auto it : m_loggermap)
|
||||
delete it.second;
|
||||
m_loggermap.clear();
|
||||
|
||||
delete NGL::NGLLogger::rootlogger_ptr;
|
||||
NGL::NGLLogger::rootlogger_ptr = nullptr;
|
||||
std::mutex &CleanupHelper::getLoggerMapMutex()
|
||||
{
|
||||
return m_loggermapmutex;
|
||||
}
|
||||
}
|
||||
|
||||
std::mutex &CleanupHelper::getLoggerMapMutex()
|
||||
{
|
||||
return m_loggermapmutex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::NGLLogger::NGLLogger(const std::string &fullqualifiedname)
|
||||
: name(fullqualifiedname)
|
||||
, currentLevel(LogLevel::Undefined)
|
||||
, m_bNoSpace(true)
|
||||
: name(fullqualifiedname)
|
||||
, currentLevel(LogLevel::Undefined)
|
||||
, m_bNoSpace(true)
|
||||
{
|
||||
#ifdef HAVE_LOG4QT
|
||||
if (!fullqualifiedname.empty())
|
||||
@@ -113,17 +104,13 @@ NGL::NGLLogger::NGLLogger(const std::string &fullqualifiedname)
|
||||
else
|
||||
{
|
||||
logger_ptr = Log4Qt::LogManager::loggerRepository()->rootLogger();
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
configChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger &NGL::NGLLogger::getNGLLogger(const char *fullqualifiedname)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_cleanup.getLoggerMapMutex());
|
||||
@@ -135,9 +122,6 @@ NGL::INGLLogger &NGL::NGLLogger::getNGLLogger(const char *fullqualifiedname)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger &NGL::NGLLogger::getNGLLogger(const std::string &fullqualifiedname)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_cleanup.getLoggerMapMutex());
|
||||
@@ -149,9 +133,6 @@ NGL::INGLLogger &NGL::NGLLogger::getNGLLogger(const std::string &fullqualifiedna
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::log(LogLevel level, const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
#ifdef HAVE_LOG4QT
|
||||
@@ -182,9 +163,6 @@ void NGL::NGLLogger::log(LogLevel level, const INGLLogger::String &message, cons
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logTrace(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
if (currentLevel >= LogLevel::Trace)
|
||||
@@ -192,9 +170,6 @@ void NGL::NGLLogger::logTrace(const INGLLogger::String &message, const char *fil
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logDebug(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
if (currentLevel >= LogLevel::Debug)
|
||||
@@ -202,9 +177,6 @@ void NGL::NGLLogger::logDebug(const INGLLogger::String &message, const char *fil
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logInfo(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
if (currentLevel >= LogLevel::Info)
|
||||
@@ -212,9 +184,6 @@ void NGL::NGLLogger::logInfo(const INGLLogger::String &message, const char *file
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logWarning(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
if (currentLevel >= LogLevel::Warning)
|
||||
@@ -222,9 +191,6 @@ void NGL::NGLLogger::logWarning(const INGLLogger::String &message, const char *f
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logError(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
if (currentLevel >= LogLevel::Error)
|
||||
@@ -232,17 +198,12 @@ void NGL::NGLLogger::logError(const INGLLogger::String &message, const char *fil
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logFatal(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
log(LogLevel::Fatal, message, file, line, function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef LTS_VERSION_MAJOR
|
||||
#define LTS_VERSION_MAJOR "undefined"
|
||||
#endif
|
||||
@@ -266,52 +227,58 @@ static const char ver_jenkins[] = JENKINS_BUILD_NUMBER;
|
||||
|
||||
void NGL::NGLLogger::logStartup(const char *file, int line, const char *function)
|
||||
{
|
||||
log(LogLevel::Info, QStringLiteral("Application is started (%1.%2-%3 rev%4 from %5)")
|
||||
.arg(QString::fromLatin1(ver_major),
|
||||
QString::fromLatin1(ver_minor),
|
||||
QString::fromLatin1(ver_jenkins),
|
||||
QString::fromLatin1(ver_patch),
|
||||
QString::fromLatin1(ver_date)).toUtf8().constData(), file, line, function);
|
||||
log(LogLevel::Info,
|
||||
QStringLiteral("Application is started (%1.%2-%3 rev%4 from %5)")
|
||||
.arg(QString::fromLatin1(ver_major),
|
||||
QString::fromLatin1(ver_minor),
|
||||
QString::fromLatin1(ver_jenkins),
|
||||
QString::fromLatin1(ver_patch),
|
||||
QString::fromLatin1(ver_date))
|
||||
.toUtf8()
|
||||
.constData(),
|
||||
file,
|
||||
line,
|
||||
function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logShutdown(const char *file, int line, const char *function)
|
||||
{
|
||||
log(LogLevel::Info, QStringLiteral("Application is shut down (%1.%2-%3 rev%4 from %5)")
|
||||
.arg(QString::fromLatin1(ver_major),
|
||||
QString::fromLatin1(ver_minor),
|
||||
QString::fromLatin1(ver_jenkins),
|
||||
QString::fromLatin1(ver_patch),
|
||||
QString::fromLatin1(ver_date)).toUtf8().constData(), file, line, function);
|
||||
log(LogLevel::Info,
|
||||
QStringLiteral("Application is shut down (%1.%2-%3 rev%4 from %5)")
|
||||
.arg(QString::fromLatin1(ver_major),
|
||||
QString::fromLatin1(ver_minor),
|
||||
QString::fromLatin1(ver_jenkins),
|
||||
QString::fromLatin1(ver_patch),
|
||||
QString::fromLatin1(ver_date))
|
||||
.toUtf8()
|
||||
.constData(),
|
||||
file,
|
||||
line,
|
||||
function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::NGLLogger &NGL::NGLLogger::getNGLRootLogger()
|
||||
{
|
||||
if (!rootlogger_ptr) throw NotCreatedError();
|
||||
if (!rootlogger_ptr)
|
||||
throw NotCreatedError();
|
||||
return *rootlogger_ptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_LOG4QT
|
||||
static QString findConfigFile(const QString &configfilename)
|
||||
{
|
||||
if (configfilename.isEmpty())
|
||||
return QString();
|
||||
|
||||
|
||||
|
||||
QFileInfo fi(configfilename);
|
||||
if (fi.isFile() && fi.isReadable())
|
||||
return fi.absoluteFilePath();
|
||||
|
||||
|
||||
|
||||
QString p = QCoreApplication::applicationDirPath() + QLatin1Char('/') + configfilename;
|
||||
fi.setFile(p);
|
||||
if (fi.isFile() && fi.isReadable())
|
||||
@@ -322,16 +289,12 @@ static QString findConfigFile(const QString &configfilename)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::NGLLogger &NGL::NGLLogger::createNGLRootLogger(const QString &configfilename,
|
||||
bool ignorealreadycreated,
|
||||
const QString &logOutputName,
|
||||
bool quiet)
|
||||
NGL::NGLLogger &NGL::NGLLogger::createNGLRootLogger(const QString &configfilename, bool ignorealreadycreated, const QString &logOutputName, bool quiet)
|
||||
{
|
||||
if (rootlogger_ptr)
|
||||
{
|
||||
if (!ignorealreadycreated) throw AlreadyCreatedError();
|
||||
if (!ignorealreadycreated)
|
||||
throw AlreadyCreatedError();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -344,8 +307,7 @@ NGL::NGLLogger &NGL::NGLLogger::createNGLRootLogger(const QString &configfilenam
|
||||
if (!filename.isEmpty())
|
||||
{
|
||||
Log4Qt::PropertyConfigurator::configureAndWatch(filename);
|
||||
QObject::connect(Log4Qt::ConfiguratorHelper::instance(), &Log4Qt::ConfiguratorHelper::configurationFileChanged,
|
||||
[]() { configurationFileChanged(); });
|
||||
QObject::connect(Log4Qt::ConfiguratorHelper::instance(), &Log4Qt::ConfiguratorHelper::configurationFileChanged, []() { configurationFileChanged(); });
|
||||
const auto l = Log4Qt::ConfiguratorHelper::instance()->configureError();
|
||||
for (const auto &t : l)
|
||||
std::cerr << t.message().toUtf8().data() << std::endl;
|
||||
@@ -355,19 +317,14 @@ NGL::NGLLogger &NGL::NGLLogger::createNGLRootLogger(const QString &configfilenam
|
||||
else
|
||||
{
|
||||
if (!quiet)
|
||||
std::cerr << "Could not find log4cxx configuration file " << configfilename << std::endl
|
||||
<< "Using default logging to stdout" << std::endl;
|
||||
std::cerr << "Could not find log4cxx configuration file " << configfilename << std::endl << "Using default logging to stdout" << std::endl;
|
||||
|
||||
|
||||
|
||||
Log4Qt::Properties props;
|
||||
props.setProperty(QLatin1String("log4j.rootLogger"),
|
||||
QLatin1String("WARN, stdout"));
|
||||
props.setProperty(QLatin1String("log4j.appender.stdout"),
|
||||
QLatin1String("org.apache.log4j.ConsoleAppender"));
|
||||
props.setProperty(QLatin1String("log4j.appender.stdout.layout"),
|
||||
QLatin1String("org.apache.log4j.PatternLayout"));
|
||||
props.setProperty(QLatin1String("log4j.appender.stdout.layout.ConversionPattern"),
|
||||
QLatin1String("%d %-5p %c |#| %m (%.50F:%L) %n"));
|
||||
props.setProperty(QLatin1String("log4j.rootLogger"), QLatin1String("WARN, stdout"));
|
||||
props.setProperty(QLatin1String("log4j.appender.stdout"), QLatin1String("org.apache.log4j.ConsoleAppender"));
|
||||
props.setProperty(QLatin1String("log4j.appender.stdout.layout"), QLatin1String("org.apache.log4j.PatternLayout"));
|
||||
props.setProperty(QLatin1String("log4j.appender.stdout.layout.ConversionPattern"), QLatin1String("%d %-5p %c |#| %m (%.50F:%L) %n"));
|
||||
Log4Qt::PropertyConfigurator::configure(props);
|
||||
}
|
||||
rootlogger_ptr->configChanged();
|
||||
@@ -407,82 +364,80 @@ void NGL::NGLLogger::configChanged()
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
namespace NGLLoggerHelper
|
||||
{
|
||||
|
||||
void hexDumpHelper(NGL::INGLLogger &logger, NGL::LogLevel level,
|
||||
const void *a_data, const unsigned int a_size)
|
||||
{
|
||||
if (!logger.isLevelEnabled(level) || !a_data)
|
||||
return;
|
||||
|
||||
unsigned char *data = (unsigned char *)a_data;
|
||||
QByteArray baBuf;
|
||||
for (unsigned int i = 0; i < a_size; i++)
|
||||
namespace NGLLoggerHelper
|
||||
{
|
||||
if (0 == (i % 8))
|
||||
baBuf = QByteArray::number(i, 16).rightJustified(8, '0').toUpper();
|
||||
baBuf += " " + QByteArray::number(data[i], 16).rightJustified(2, '0').toUpper();
|
||||
if (7 == (i % 8))
|
||||
logger.log(level, baBuf.constData(), __FILE__, __LINE__);
|
||||
|
||||
void hexDumpHelper(NGL::INGLLogger &logger, NGL::LogLevel level, const void *a_data, const unsigned int a_size)
|
||||
{
|
||||
if (!logger.isLevelEnabled(level) || !a_data)
|
||||
return;
|
||||
|
||||
unsigned char *data = (unsigned char *)a_data;
|
||||
QByteArray baBuf;
|
||||
for (unsigned int i = 0; i < a_size; i++)
|
||||
{
|
||||
if (0 == (i % 8))
|
||||
baBuf = QByteArray::number(i, 16).rightJustified(8, '0').toUpper();
|
||||
baBuf += " " + QByteArray::number(data[i], 16).rightJustified(2, '0').toUpper();
|
||||
if (7 == (i % 8))
|
||||
logger.log(level, baBuf.constData(), __FILE__, __LINE__);
|
||||
}
|
||||
if (a_size % 8)
|
||||
logger.log(level, baBuf.constData(), __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
}
|
||||
if (a_size % 8)
|
||||
logger.log(level, baBuf.constData(), __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
NGL::INGLLogger& getMemoryLogger()
|
||||
{
|
||||
try
|
||||
NGL::INGLLogger &getMemoryLogger()
|
||||
{
|
||||
return NGLLogger::getNGLRootLogger().getNGLLogger("memorystate");
|
||||
|
||||
try
|
||||
{
|
||||
return NGLLogger::getNGLRootLogger().getNGLLogger("memorystate");
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
||||
abort();
|
||||
}
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
|
||||
int parseLine(char *line)
|
||||
{
|
||||
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
||||
abort();
|
||||
|
||||
int i = strlen(line);
|
||||
const char *p = line;
|
||||
while (*p < '0' || *p > '9')
|
||||
p++;
|
||||
line[i - 3] = '\0';
|
||||
i = atoi(p);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
int parseLine(char* line){
|
||||
|
||||
int i = strlen(line);
|
||||
const char* p = line;
|
||||
while (*p <'0' || *p > '9') p++;
|
||||
line[i-3] = '\0';
|
||||
i = atoi(p);
|
||||
return i;
|
||||
}
|
||||
int getMemoryValue()
|
||||
{
|
||||
|
||||
int getMemoryValue()
|
||||
{
|
||||
|
||||
FILE* file = fopen("/proc/self/status", "r");
|
||||
int result = -1;
|
||||
char line[128];
|
||||
FILE *file = fopen("/proc/self/status", "r");
|
||||
int result = -1;
|
||||
char line[128];
|
||||
|
||||
while (fgets(line, 128, file) != NULL){
|
||||
while (fgets(line, 128, file) != NULL)
|
||||
{
|
||||
|
||||
if (strncmp(line, "VmRSS:", 6) == 0){
|
||||
if (strncmp(line, "VmRSS:", 6) == 0)
|
||||
{
|
||||
result = parseLine(line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string getMemoryData()
|
||||
{
|
||||
return QStringLiteral("VmRSS: %1 kB #").arg(QString::number(getMemoryValue())).toStdString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::string getMemoryData()
|
||||
{
|
||||
return QStringLiteral("VmRSS: %1 kB #").arg(QString::number(getMemoryValue())).toStdString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+67
-62
@@ -21,85 +21,90 @@
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
class CleanupHelper;
|
||||
class CleanupHelper;
|
||||
|
||||
#ifdef HAVE_LOG4QT
|
||||
class LtsRollingFileAppender final : public Log4Qt::RollingFileAppender
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using Log4Qt::RollingFileAppender::RollingFileAppender;
|
||||
class LtsRollingFileAppender final : public Log4Qt::RollingFileAppender
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using Log4Qt::RollingFileAppender::RollingFileAppender;
|
||||
#else
|
||||
class LtsRollingFileAppender final : public Log4Qt::RollingFileAppender
|
||||
{
|
||||
public:
|
||||
explicit LtsRollingFileAppender(QObject *parent = nullptr) : Log4Qt::RollingFileAppender(parent) {}
|
||||
class LtsRollingFileAppender final : public Log4Qt::RollingFileAppender
|
||||
{
|
||||
public:
|
||||
explicit LtsRollingFileAppender(QObject *parent = nullptr)
|
||||
: Log4Qt::RollingFileAppender(parent)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
static void setLtsLogfileName(const QString <sLogfileName);
|
||||
void activateOptions() override;
|
||||
private:
|
||||
static QString m_ltsLogfileName;
|
||||
};
|
||||
static void setLtsLogfileName(const QString <sLogfileName);
|
||||
void activateOptions() override;
|
||||
|
||||
class NGLLogger final : public INGLLogger
|
||||
{
|
||||
explicit NGLLogger(const std::string &fullqualifiedname);
|
||||
public:
|
||||
private:
|
||||
static QString m_ltsLogfileName;
|
||||
};
|
||||
|
||||
class NotCreatedError {};
|
||||
class AlreadyCreatedError {};
|
||||
class NGLLogger final : public INGLLogger
|
||||
{
|
||||
explicit NGLLogger(const std::string &fullqualifiedname);
|
||||
|
||||
INGLLogger &getNGLLogger(const char *fullqualifiedname) override;
|
||||
INGLLogger &getNGLLogger(const std::string &fullqualifiedname) override;
|
||||
public:
|
||||
class NotCreatedError
|
||||
{
|
||||
};
|
||||
class AlreadyCreatedError
|
||||
{
|
||||
};
|
||||
|
||||
inline bool isTraceEnabled() const override { return currentLevel <= LogLevel::Trace; }
|
||||
inline bool isDebugEnabled() const override { return currentLevel <= LogLevel::Debug; }
|
||||
inline bool isInfoEnabled() const override { return currentLevel <= LogLevel::Info; }
|
||||
inline bool isWarningEnabled() const override { return currentLevel <= LogLevel::Warning; }
|
||||
inline bool isErrorEnabled() const override { return currentLevel <= LogLevel::Error; }
|
||||
inline bool isFatalEnabled() const override { return currentLevel <= LogLevel::Fatal; }
|
||||
inline bool isLevelEnabled(LogLevel level) const override { return currentLevel <= level; }
|
||||
INGLLogger &getNGLLogger(const char *fullqualifiedname) override;
|
||||
INGLLogger &getNGLLogger(const std::string &fullqualifiedname) override;
|
||||
|
||||
void log(LogLevel level, const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logTrace(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logDebug(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logInfo(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logWarning(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logError(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logFatal(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
inline bool isTraceEnabled() const override { return currentLevel <= LogLevel::Trace; }
|
||||
inline bool isDebugEnabled() const override { return currentLevel <= LogLevel::Debug; }
|
||||
inline bool isInfoEnabled() const override { return currentLevel <= LogLevel::Info; }
|
||||
inline bool isWarningEnabled() const override { return currentLevel <= LogLevel::Warning; }
|
||||
inline bool isErrorEnabled() const override { return currentLevel <= LogLevel::Error; }
|
||||
inline bool isFatalEnabled() const override { return currentLevel <= LogLevel::Fatal; }
|
||||
inline bool isLevelEnabled(LogLevel level) const override { return currentLevel <= level; }
|
||||
|
||||
void logStartup(const char *file, int line, const char *function = nullptr) override;
|
||||
void logShutdown(const char *file, int line, const char *function = nullptr) override;
|
||||
void log(LogLevel level, const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logTrace(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logDebug(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logInfo(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logWarning(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logError(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logFatal(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
|
||||
inline void setNoSpace(bool bNoSpace) override { m_bNoSpace = bNoSpace; }
|
||||
inline bool noSpace() const override { return m_bNoSpace; }
|
||||
void logStartup(const char *file, int line, const char *function = nullptr) override;
|
||||
void logShutdown(const char *file, int line, const char *function = nullptr) override;
|
||||
|
||||
inline std::string getLoggerName() const override { return name; }
|
||||
inline void setNoSpace(bool bNoSpace) override { m_bNoSpace = bNoSpace; }
|
||||
inline bool noSpace() const override { return m_bNoSpace; }
|
||||
|
||||
static NGLLogger &getNGLRootLogger();
|
||||
static NGLLogger &createNGLRootLogger(const QString &configfilename,
|
||||
bool ignorealreadycreated,
|
||||
const QString &logOutputName = QString(),
|
||||
bool quiet = false);
|
||||
inline std::string getLoggerName() const override { return name; }
|
||||
|
||||
Log4Qt::Logger *log4qtLogger() { return logger_ptr; }
|
||||
protected:
|
||||
static void configurationFileChanged();
|
||||
void configChanged();
|
||||
static NGLLogger &getNGLRootLogger();
|
||||
static NGLLogger &createNGLRootLogger(const QString &configfilename, bool ignorealreadycreated, const QString &logOutputName = QString(), bool quiet = false);
|
||||
|
||||
private:
|
||||
Log4Qt::Logger *log4qtLogger() { return logger_ptr; }
|
||||
|
||||
Log4Qt::Logger *logger_ptr;
|
||||
const std::string name;
|
||||
LogLevel currentLevel;
|
||||
bool m_bNoSpace;
|
||||
protected:
|
||||
static void configurationFileChanged();
|
||||
void configChanged();
|
||||
|
||||
static NGLLogger *rootlogger_ptr;
|
||||
private:
|
||||
Log4Qt::Logger *logger_ptr;
|
||||
const std::string name;
|
||||
LogLevel currentLevel;
|
||||
bool m_bNoSpace;
|
||||
|
||||
friend class CleanupHelper;
|
||||
static CleanupHelper s_cleanup;
|
||||
static NGLLogger *rootlogger_ptr;
|
||||
|
||||
friend class XMLWatchdog;
|
||||
};
|
||||
friend class CleanupHelper;
|
||||
static CleanupHelper s_cleanup;
|
||||
|
||||
}
|
||||
friend class XMLWatchdog;
|
||||
};
|
||||
|
||||
}
|
||||
Executable → Regular
+2
-15
@@ -5,26 +5,13 @@
|
||||
#include "NGLLogger.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger & NGL::NGLLoggerBootstrap::getNGLRootLogger()
|
||||
NGL::INGLLogger &NGL::NGLLoggerBootstrap::getNGLRootLogger()
|
||||
{
|
||||
return NGL::NGLLogger::getNGLRootLogger();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger & NGL::NGLLoggerBootstrap::createNGLRootLogger(const QString &configfilename,
|
||||
bool ignorealreadycreated,
|
||||
const QString &logOutputName,
|
||||
bool quiet)
|
||||
NGL::INGLLogger &NGL::NGLLoggerBootstrap::createNGLRootLogger(const QString &configfilename, bool ignorealreadycreated, const QString &logOutputName, bool quiet)
|
||||
{
|
||||
return NGL::NGLLogger::createNGLRootLogger(configfilename, ignorealreadycreated, logOutputName, quiet);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,36 +9,31 @@
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
namespace NGLLoggerBootstrap
|
||||
{
|
||||
class AlreadyCreatedError final : public std::exception
|
||||
{
|
||||
const char* what() const noexcept override
|
||||
namespace NGLLoggerBootstrap
|
||||
{
|
||||
class AlreadyCreatedError final : public std::exception
|
||||
{
|
||||
return "NGLLogger rootlogger already created!";
|
||||
}
|
||||
};
|
||||
const char *what() const noexcept override { return "NGLLogger rootlogger already created!"; }
|
||||
};
|
||||
|
||||
class NotCreatedError final : public std::exception
|
||||
{
|
||||
const char* what() const noexcept override
|
||||
class NotCreatedError final : public std::exception
|
||||
{
|
||||
return "NGLLogger rootlogger not yet created!";
|
||||
const char *what() const noexcept override { return "NGLLogger rootlogger not yet created!"; }
|
||||
};
|
||||
|
||||
NGLLOGGER_EXPORT INGLLogger &getNGLRootLogger();
|
||||
|
||||
NGLLOGGER_EXPORT INGLLogger &createNGLRootLogger(const QString &configfilename,
|
||||
bool ignorealreadycreated,
|
||||
const QString &logOutputName = QString(),
|
||||
bool quiet = false);
|
||||
|
||||
inline INGLLogger &createNGLRootLogger(const char *configfilename, bool ignorealreadycreated, const QString &logOutputName = QString())
|
||||
{
|
||||
return createNGLRootLogger(QString::fromUtf8(configfilename), ignorealreadycreated, logOutputName);
|
||||
}
|
||||
};
|
||||
|
||||
NGLLOGGER_EXPORT INGLLogger& getNGLRootLogger();
|
||||
|
||||
NGLLOGGER_EXPORT INGLLogger& createNGLRootLogger(const QString& configfilename, bool ignorealreadycreated,
|
||||
const QString& logOutputName = QString(), bool quiet = false);
|
||||
|
||||
inline INGLLogger& createNGLRootLogger(const char* configfilename, bool ignorealreadycreated,
|
||||
const QString& logOutputName = QString())
|
||||
{
|
||||
return createNGLRootLogger(QString::fromUtf8(configfilename), ignorealreadycreated, logOutputName);
|
||||
}
|
||||
|
||||
} // namespace NGLLoggerBootstrap
|
||||
} // namespace NGLLoggerBootstrap
|
||||
|
||||
} // namespace NGL
|
||||
|
||||
|
||||
Executable → Regular
+14
-14
@@ -4,19 +4,19 @@
|
||||
#define NGLLOGGER_EXPORT_H
|
||||
|
||||
#ifndef NGLLOGGER_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLLOGGER_EXPORT
|
||||
# else
|
||||
# ifdef WIN32
|
||||
# ifdef MAKE_NGLLOGGER_LIB
|
||||
# define NGLLOGGER_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define NGLLOGGER_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define NGLLOGGER_EXPORT __attribute__((visibility("default")))
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLLOGGER_EXPORT
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#ifdef MAKE_NGLLOGGER_LIB
|
||||
#define NGLLOGGER_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define NGLLOGGER_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define NGLLOGGER_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -8,106 +8,123 @@
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Log4Qt {
|
||||
|
||||
// Minimal Logger class stub (no Q_OBJECT to avoid MOC requirements)
|
||||
class Logger
|
||||
namespace Log4Qt
|
||||
{
|
||||
public:
|
||||
|
||||
// Minimal Logger class stub (no Q_OBJECT to avoid MOC requirements)
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
explicit Logger(QObject *parent = nullptr) { Q_UNUSED(parent); }
|
||||
virtual ~Logger() = default;
|
||||
|
||||
|
||||
inline void trace(const QString &message) { Q_UNUSED(message); }
|
||||
inline void debug(const QString &message) { qDebug() << message; }
|
||||
inline void info(const QString &message) { qDebug() << message; }
|
||||
inline void warning(const QString &message) { qWarning() << message; }
|
||||
inline void error(const QString &message) { qCritical() << message; }
|
||||
inline void fatal(const QString &message) { qCritical() << message; }
|
||||
|
||||
|
||||
inline bool isTraceEnabled() const { return true; }
|
||||
inline bool isDebugEnabled() const { return true; }
|
||||
inline bool isInfoEnabled() const { return true; }
|
||||
inline bool isWarnEnabled() const { return true; }
|
||||
inline bool isErrorEnabled() const { return true; }
|
||||
};
|
||||
};
|
||||
|
||||
// Minimal RollingFileAppender stub
|
||||
class RollingFileAppender : public Logger
|
||||
{
|
||||
public:
|
||||
explicit RollingFileAppender(QObject *parent = nullptr) : Logger(parent) {}
|
||||
// Minimal RollingFileAppender stub
|
||||
class RollingFileAppender : public Logger
|
||||
{
|
||||
public:
|
||||
explicit RollingFileAppender(QObject *parent = nullptr)
|
||||
: Logger(parent)
|
||||
{
|
||||
}
|
||||
~RollingFileAppender() override = default;
|
||||
|
||||
|
||||
inline void setFile(const QString &filename) { Q_UNUSED(filename); }
|
||||
inline void setAppendFile(bool append) { Q_UNUSED(append); }
|
||||
virtual void activateOptions() {}
|
||||
};
|
||||
};
|
||||
|
||||
// Minimal LogManager stub
|
||||
class LogManager
|
||||
{
|
||||
public:
|
||||
static LogManager *instance() {
|
||||
static LogManager inst;
|
||||
return &inst;
|
||||
// Minimal LogManager stub
|
||||
class LogManager
|
||||
{
|
||||
public:
|
||||
static LogManager *instance()
|
||||
{
|
||||
static LogManager inst;
|
||||
return &inst;
|
||||
}
|
||||
|
||||
Logger *logger(const QString &name) {
|
||||
static Logger dummy;
|
||||
Q_UNUSED(name);
|
||||
return &dummy;
|
||||
|
||||
Logger *logger(const QString &name)
|
||||
{
|
||||
static Logger dummy;
|
||||
Q_UNUSED(name);
|
||||
return &dummy;
|
||||
}
|
||||
|
||||
|
||||
void setDefaultLogger(Logger *logger) { Q_UNUSED(logger); }
|
||||
};
|
||||
};
|
||||
|
||||
// Minimal PropertyConfigurator stub
|
||||
class PropertyConfigurator
|
||||
{
|
||||
public:
|
||||
static bool doConfigure(const QString &configFile) {
|
||||
Q_UNUSED(configFile);
|
||||
return false;
|
||||
// Minimal PropertyConfigurator stub
|
||||
class PropertyConfigurator
|
||||
{
|
||||
public:
|
||||
static bool doConfigure(const QString &configFile)
|
||||
{
|
||||
Q_UNUSED(configFile);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Minimal LoggerRepository stub
|
||||
class LoggerRepository
|
||||
{
|
||||
public:
|
||||
// Minimal LoggerRepository stub
|
||||
class LoggerRepository
|
||||
{
|
||||
public:
|
||||
inline void setThreshold(int level) { Q_UNUSED(level); }
|
||||
};
|
||||
};
|
||||
|
||||
// Minimal ConfiguratorHelper stub
|
||||
namespace Helpers {
|
||||
class ConfiguratorHelper {
|
||||
// Minimal ConfiguratorHelper stub
|
||||
namespace Helpers
|
||||
{
|
||||
class ConfiguratorHelper
|
||||
{
|
||||
public:
|
||||
static ConfiguratorHelper *instance() {
|
||||
static ConfiguratorHelper inst;
|
||||
return &inst;
|
||||
}
|
||||
static ConfiguratorHelper *instance()
|
||||
{
|
||||
static ConfiguratorHelper inst;
|
||||
return &inst;
|
||||
}
|
||||
};
|
||||
|
||||
class Properties {
|
||||
|
||||
class Properties
|
||||
{
|
||||
public:
|
||||
Properties() {}
|
||||
inline void setProperty(const QString &key, const QString &value) {
|
||||
Q_UNUSED(key); Q_UNUSED(value);
|
||||
}
|
||||
Properties() {}
|
||||
inline void setProperty(const QString &key, const QString &value)
|
||||
{
|
||||
Q_UNUSED(key);
|
||||
Q_UNUSED(value);
|
||||
}
|
||||
};
|
||||
|
||||
class Factory {
|
||||
|
||||
class Factory
|
||||
{
|
||||
public:
|
||||
static Factory *instance() {
|
||||
static Factory inst;
|
||||
return &inst;
|
||||
}
|
||||
inline void registerAppender(const QString &name, void *creator) {
|
||||
Q_UNUSED(name); Q_UNUSED(creator);
|
||||
}
|
||||
static Factory *instance()
|
||||
{
|
||||
static Factory inst;
|
||||
return &inst;
|
||||
}
|
||||
inline void registerAppender(const QString &name, void *creator)
|
||||
{
|
||||
Q_UNUSED(name);
|
||||
Q_UNUSED(creator);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Log4Qt
|
||||
|
||||
#endif // LOG4QT_STUB_H
|
||||
#endif // LOG4QT_STUB_H
|
||||
Executable → Regular
+14
-14
@@ -8,26 +8,26 @@ int main(int argc, char **argv)
|
||||
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger("log4cxx.props", false);
|
||||
|
||||
NGL::INGLLogger &l = NGL::NGLLoggerBootstrap::getNGLRootLogger(). getNGLLogger( "Gui" );
|
||||
NGL::INGLLogger &l = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui");
|
||||
|
||||
STARTUP_LOG(l);
|
||||
SHUTDOWN_LOG(l);
|
||||
NOTICE_LOG(l) << "Gui - NOTICE";
|
||||
TRACE_LOG(l) << "Gui - TRACE";
|
||||
DEBUG_LOG(l) << "Gui - DEBUG";
|
||||
INFO_LOG(l) << "Gui - INFO";
|
||||
NOTICE_LOG(l) << "Gui - NOTICE";
|
||||
TRACE_LOG(l) << "Gui - TRACE";
|
||||
DEBUG_LOG(l) << "Gui - DEBUG";
|
||||
INFO_LOG(l) << "Gui - INFO";
|
||||
WARNING_LOG(l) << "Gui - WARNING";
|
||||
ERROR_LOG(l) << "Gui - ERROR";
|
||||
FATAL_LOG(l) << "Gui - FATAL";
|
||||
ERROR_LOG(l) << "Gui - ERROR";
|
||||
FATAL_LOG(l) << "Gui - FATAL";
|
||||
|
||||
NGL::INGLLogger &l2 = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger( "Gui.AES" );
|
||||
NOTICE_LOG(l2) << "Gui.AES - NOTICE";
|
||||
TRACE_LOG(l2) << "Gui.AES - TRACE";
|
||||
DEBUG_LOG(l2) << "Gui.AES - DEBUG";
|
||||
INFO_LOG(l2) << "Gui.AES - INFO";
|
||||
NGL::INGLLogger &l2 = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Gui.AES");
|
||||
NOTICE_LOG(l2) << "Gui.AES - NOTICE";
|
||||
TRACE_LOG(l2) << "Gui.AES - TRACE";
|
||||
DEBUG_LOG(l2) << "Gui.AES - DEBUG";
|
||||
INFO_LOG(l2) << "Gui.AES - INFO";
|
||||
WARNING_LOG(l2) << "Gui.AES - WARNING";
|
||||
ERROR_LOG(l2) << "Gui.AES - ERROR";
|
||||
FATAL_LOG(l2) << "Gui.AES - FATAL";
|
||||
ERROR_LOG(l2) << "Gui.AES - ERROR";
|
||||
FATAL_LOG(l2) << "Gui.AES - FATAL";
|
||||
SHUTDOWN_LOG(l2)
|
||||
|
||||
return 0;
|
||||
|
||||
Executable → Regular
+113
-108
@@ -1,7 +1,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include "qtlocalpeer.h"
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QDataStream>
|
||||
@@ -11,7 +10,7 @@
|
||||
#if defined(Q_OS_WIN)
|
||||
#include <QtCore/QLibrary>
|
||||
#include <qt_windows.h>
|
||||
typedef BOOL(WINAPI*PProcessIdToSessionId)(DWORD,DWORD*);
|
||||
typedef BOOL(WINAPI *PProcessIdToSessionId)(DWORD, DWORD *);
|
||||
static PProcessIdToSessionId pProcessIdToSessionId = 0;
|
||||
#endif
|
||||
#if defined(Q_OS_UNIX)
|
||||
@@ -20,7 +19,8 @@ static PProcessIdToSessionId pProcessIdToSessionId = 0;
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace QtLP_Private {
|
||||
namespace QtLP_Private
|
||||
{
|
||||
#include "qtlockedfile.cpp"
|
||||
#if defined(Q_OS_WIN)
|
||||
#include "qtlockedfile_win.cpp"
|
||||
@@ -29,142 +29,147 @@ namespace QtLP_Private {
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* QtLocalPeer::ack = "ack";
|
||||
const char *QtLocalPeer::ack = "ack";
|
||||
|
||||
QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId)
|
||||
: QObject(parent), id(appId)
|
||||
QtLocalPeer::QtLocalPeer(QObject *parent, const QString &appId)
|
||||
: QObject(parent)
|
||||
, id(appId)
|
||||
{
|
||||
QString prefix = id;
|
||||
if (id.isEmpty()) {
|
||||
id = QCoreApplication::applicationFilePath();
|
||||
QString prefix = id;
|
||||
if (id.isEmpty())
|
||||
{
|
||||
id = QCoreApplication::applicationFilePath();
|
||||
#if defined(Q_OS_WIN)
|
||||
id = id.toLower();
|
||||
id = id.toLower();
|
||||
#endif
|
||||
prefix = id.section(QLatin1Char('/'), -1);
|
||||
}
|
||||
// QRegExp is removed in Qt6; use QRegularExpression
|
||||
prefix.remove(QRegularExpression(QLatin1String("[^a-zA-Z]")));
|
||||
prefix.truncate(6);
|
||||
prefix = id.section(QLatin1Char('/'), -1);
|
||||
}
|
||||
// QRegExp is removed in Qt6; use QRegularExpression
|
||||
prefix.remove(QRegularExpression(QLatin1String("[^a-zA-Z]")));
|
||||
prefix.truncate(6);
|
||||
|
||||
QByteArray idc = id.toUtf8();
|
||||
// Use QByteArrayView overload to avoid deprecated qChecksum overload
|
||||
quint16 idNum = qChecksum(QByteArrayView(idc));
|
||||
socketName = QLatin1String("qtsingleapp-") + prefix
|
||||
+ QLatin1Char('-') + QString::number(idNum, 16);
|
||||
QByteArray idc = id.toUtf8();
|
||||
// Use QByteArrayView overload to avoid deprecated qChecksum overload
|
||||
quint16 idNum = qChecksum(QByteArrayView(idc));
|
||||
socketName = QLatin1String("qtsingleapp-") + prefix + QLatin1Char('-') + QString::number(idNum, 16);
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
if (!pProcessIdToSessionId) {
|
||||
QLibrary lib(QLatin1String("kernel32"));
|
||||
pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId");
|
||||
}
|
||||
if (pProcessIdToSessionId) {
|
||||
DWORD sessionId = 0;
|
||||
pProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
|
||||
socketName += QLatin1Char('-') + QString::number(sessionId, 16);
|
||||
}
|
||||
if (!pProcessIdToSessionId)
|
||||
{
|
||||
QLibrary lib(QLatin1String("kernel32"));
|
||||
pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId");
|
||||
}
|
||||
if (pProcessIdToSessionId)
|
||||
{
|
||||
DWORD sessionId = 0;
|
||||
pProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
|
||||
socketName += QLatin1Char('-') + QString::number(sessionId, 16);
|
||||
}
|
||||
#else
|
||||
socketName += QLatin1Char('-') + QString::number(::getuid(), 16);
|
||||
socketName += QLatin1Char('-') + QString::number(::getuid(), 16);
|
||||
#endif
|
||||
|
||||
server = new QLocalServer(this);
|
||||
QString lockName = QDir(QDir::tempPath()).absolutePath()
|
||||
+ QLatin1Char('/') + socketName
|
||||
+ QLatin1String("-lockfile");
|
||||
lockFile.setFileName(lockName);
|
||||
lockFile.open(QIODevice::ReadWrite);
|
||||
server = new QLocalServer(this);
|
||||
QString lockName = QDir(QDir::tempPath()).absolutePath() + QLatin1Char('/') + socketName + QLatin1String("-lockfile");
|
||||
lockFile.setFileName(lockName);
|
||||
lockFile.open(QIODevice::ReadWrite);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool QtLocalPeer::isClient()
|
||||
{
|
||||
if (lockFile.isLocked())
|
||||
return false;
|
||||
|
||||
if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false))
|
||||
return true;
|
||||
|
||||
bool res = server->listen(socketName);
|
||||
#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0))
|
||||
|
||||
if (!res && server->serverError() == QAbstractSocket::AddressInUseError) {
|
||||
QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName);
|
||||
res = server->listen(socketName);
|
||||
}
|
||||
#endif
|
||||
if (!res)
|
||||
qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString()));
|
||||
QObject::connect(server, &QLocalServer::newConnection, this, &QtLocalPeer::receiveConnection);
|
||||
if (lockFile.isLocked())
|
||||
return false;
|
||||
|
||||
if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false))
|
||||
return true;
|
||||
|
||||
bool res = server->listen(socketName);
|
||||
#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4, 5, 0))
|
||||
|
||||
if (!res && server->serverError() == QAbstractSocket::AddressInUseError)
|
||||
{
|
||||
QFile::remove(QDir::cleanPath(QDir::tempPath()) + QLatin1Char('/') + socketName);
|
||||
res = server->listen(socketName);
|
||||
}
|
||||
#endif
|
||||
if (!res)
|
||||
qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString()));
|
||||
QObject::connect(server, &QLocalServer::newConnection, this, &QtLocalPeer::receiveConnection);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool QtLocalPeer::sendMessage(const QString &message, int timeout)
|
||||
{
|
||||
if (!isClient())
|
||||
return false;
|
||||
if (!isClient())
|
||||
return false;
|
||||
|
||||
QLocalSocket socket;
|
||||
bool connOk = false;
|
||||
for(int i = 0; i < 2; i++) {
|
||||
|
||||
socket.connectToServer(socketName);
|
||||
connOk = socket.waitForConnected(timeout/2);
|
||||
if (connOk || i)
|
||||
break;
|
||||
int ms = 250;
|
||||
QLocalSocket socket;
|
||||
bool connOk = false;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
|
||||
socket.connectToServer(socketName);
|
||||
connOk = socket.waitForConnected(timeout / 2);
|
||||
if (connOk || i)
|
||||
break;
|
||||
int ms = 250;
|
||||
#if defined(Q_OS_WIN)
|
||||
Sleep(DWORD(ms));
|
||||
Sleep(DWORD(ms));
|
||||
#else
|
||||
struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
|
||||
nanosleep(&ts, nullptr);
|
||||
struct timespec ts = {ms / 1000, (ms % 1000) * 1000 * 1000};
|
||||
nanosleep(&ts, nullptr);
|
||||
#endif
|
||||
}
|
||||
if (!connOk)
|
||||
return false;
|
||||
}
|
||||
if (!connOk)
|
||||
return false;
|
||||
|
||||
QByteArray uMsg(message.toUtf8());
|
||||
QDataStream ds(&socket);
|
||||
ds.writeBytes(uMsg.constData(), uMsg.size());
|
||||
bool res = socket.waitForBytesWritten(timeout);
|
||||
if (res) {
|
||||
res &= socket.waitForReadyRead(timeout);
|
||||
if (res)
|
||||
res &= (socket.read(qstrlen(ack)) == ack);
|
||||
}
|
||||
return res;
|
||||
QByteArray uMsg(message.toUtf8());
|
||||
QDataStream ds(&socket);
|
||||
ds.writeBytes(uMsg.constData(), uMsg.size());
|
||||
bool res = socket.waitForBytesWritten(timeout);
|
||||
if (res)
|
||||
{
|
||||
res &= socket.waitForReadyRead(timeout);
|
||||
if (res)
|
||||
res &= (socket.read(qstrlen(ack)) == ack);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void QtLocalPeer::receiveConnection()
|
||||
{
|
||||
QLocalSocket* socket = server->nextPendingConnection();
|
||||
if (!socket)
|
||||
return;
|
||||
QLocalSocket *socket = server->nextPendingConnection();
|
||||
if (!socket)
|
||||
return;
|
||||
|
||||
while (socket->bytesAvailable() < (int)sizeof(quint32))
|
||||
socket->waitForReadyRead();
|
||||
QDataStream ds(socket);
|
||||
QByteArray uMsg;
|
||||
quint32 remaining;
|
||||
ds >> remaining;
|
||||
uMsg.resize(remaining);
|
||||
int got = 0;
|
||||
char* uMsgBuf = uMsg.data();
|
||||
do {
|
||||
got = ds.readRawData(uMsgBuf, remaining);
|
||||
remaining -= got;
|
||||
uMsgBuf += got;
|
||||
} while (remaining && got >= 0 && socket->waitForReadyRead(2000));
|
||||
if (got < 0) {
|
||||
qWarning("QtLocalPeer: Message reception failed %s", socket->errorString().toLatin1().constData());
|
||||
delete socket;
|
||||
return;
|
||||
}
|
||||
QString message(QString::fromUtf8(uMsg));
|
||||
socket->write(ack, qstrlen(ack));
|
||||
socket->waitForBytesWritten(1000);
|
||||
socket->waitForDisconnected(1000);
|
||||
while (socket->bytesAvailable() < (int)sizeof(quint32))
|
||||
socket->waitForReadyRead();
|
||||
QDataStream ds(socket);
|
||||
QByteArray uMsg;
|
||||
quint32 remaining;
|
||||
ds >> remaining;
|
||||
uMsg.resize(remaining);
|
||||
int got = 0;
|
||||
char *uMsgBuf = uMsg.data();
|
||||
do
|
||||
{
|
||||
got = ds.readRawData(uMsgBuf, remaining);
|
||||
remaining -= got;
|
||||
uMsgBuf += got;
|
||||
} while (remaining && got >= 0 && socket->waitForReadyRead(2000));
|
||||
if (got < 0)
|
||||
{
|
||||
qWarning("QtLocalPeer: Message reception failed %s", socket->errorString().toLatin1().constData());
|
||||
delete socket;
|
||||
emit messageReceived(message);
|
||||
return;
|
||||
}
|
||||
QString message(QString::fromUtf8(uMsg));
|
||||
socket->write(ack, qstrlen(ack));
|
||||
socket->waitForBytesWritten(1000);
|
||||
socket->waitForDisconnected(1000);
|
||||
delete socket;
|
||||
emit messageReceived(message);
|
||||
}
|
||||
Executable → Regular
+13
-14
@@ -12,29 +12,28 @@
|
||||
|
||||
class QtLocalPeer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtLocalPeer(QObject *parent = nullptr, const QString &appId = QString());
|
||||
bool isClient();
|
||||
bool sendMessage(const QString &message, int timeout);
|
||||
QString applicationId() const
|
||||
{ return id; }
|
||||
QtLocalPeer(QObject *parent = nullptr, const QString &appId = QString());
|
||||
bool isClient();
|
||||
bool sendMessage(const QString &message, int timeout);
|
||||
QString applicationId() const { return id; }
|
||||
|
||||
Q_SIGNALS:
|
||||
void messageReceived(const QString &message);
|
||||
void messageReceived(const QString &message);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void receiveConnection();
|
||||
void receiveConnection();
|
||||
|
||||
protected:
|
||||
QString id;
|
||||
QString socketName;
|
||||
QLocalServer* server;
|
||||
QtLP_Private::QtLockedFile lockFile;
|
||||
QString id;
|
||||
QString socketName;
|
||||
QLocalServer *server;
|
||||
QtLP_Private::QtLockedFile lockFile;
|
||||
|
||||
private:
|
||||
static const char* ack;
|
||||
static const char *ack;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+14
-33
@@ -4,65 +4,46 @@
|
||||
#include "qtlockedfile.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QtLockedFile::QtLockedFile()
|
||||
: QFile()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
wmutex = 0;
|
||||
rmutex = 0;
|
||||
wmutex = 0;
|
||||
rmutex = 0;
|
||||
#endif
|
||||
m_lock_mode = NoLock;
|
||||
m_lock_mode = NoLock;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QtLockedFile::QtLockedFile(const QString &name)
|
||||
: QFile(name)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
wmutex = 0;
|
||||
rmutex = 0;
|
||||
wmutex = 0;
|
||||
rmutex = 0;
|
||||
#endif
|
||||
m_lock_mode = NoLock;
|
||||
m_lock_mode = NoLock;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool QtLockedFile::open(OpenMode mode)
|
||||
{
|
||||
if (mode & QIODevice::Truncate) {
|
||||
qWarning("QtLockedFile::open(): Truncate mode not allowed.");
|
||||
return false;
|
||||
}
|
||||
return QFile::open(mode);
|
||||
if (mode & QIODevice::Truncate)
|
||||
{
|
||||
qWarning("QtLockedFile::open(): Truncate mode not allowed.");
|
||||
return false;
|
||||
}
|
||||
return QFile::open(mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool QtLockedFile::isLocked() const
|
||||
{
|
||||
return m_lock_mode != NoLock;
|
||||
return m_lock_mode != NoLock;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QtLockedFile::LockMode QtLockedFile::lockMode() const
|
||||
{
|
||||
return m_lock_mode;
|
||||
return m_lock_mode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+25
-19
@@ -10,27 +10,33 @@
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
# if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT)
|
||||
# define QT_QTLOCKEDFILE_EXPORT
|
||||
# elif defined(QT_QTLOCKEDFILE_IMPORT)
|
||||
# if defined(QT_QTLOCKEDFILE_EXPORT)
|
||||
# undef QT_QTLOCKEDFILE_EXPORT
|
||||
# endif
|
||||
# define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport)
|
||||
# elif defined(QT_QTLOCKEDFILE_EXPORT)
|
||||
# undef QT_QTLOCKEDFILE_EXPORT
|
||||
# define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport)
|
||||
# endif
|
||||
#if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT)
|
||||
#define QT_QTLOCKEDFILE_EXPORT
|
||||
#elif defined(QT_QTLOCKEDFILE_IMPORT)
|
||||
#if defined(QT_QTLOCKEDFILE_EXPORT)
|
||||
#undef QT_QTLOCKEDFILE_EXPORT
|
||||
#endif
|
||||
#define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport)
|
||||
#elif defined(QT_QTLOCKEDFILE_EXPORT)
|
||||
#undef QT_QTLOCKEDFILE_EXPORT
|
||||
#define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport)
|
||||
#endif
|
||||
#else
|
||||
# define QT_QTLOCKEDFILE_EXPORT
|
||||
#define QT_QTLOCKEDFILE_EXPORT
|
||||
#endif
|
||||
|
||||
namespace QtLP_Private {
|
||||
|
||||
class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile
|
||||
namespace QtLP_Private
|
||||
{
|
||||
public:
|
||||
enum LockMode { NoLock = 0, ReadLock, WriteLock };
|
||||
|
||||
class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile
|
||||
{
|
||||
public:
|
||||
enum LockMode
|
||||
{
|
||||
NoLock = 0,
|
||||
ReadLock,
|
||||
WriteLock
|
||||
};
|
||||
|
||||
QtLockedFile();
|
||||
explicit QtLockedFile(const QString &name);
|
||||
@@ -43,7 +49,7 @@ public:
|
||||
bool isLocked() const;
|
||||
LockMode lockMode() const;
|
||||
|
||||
private:
|
||||
private:
|
||||
#ifdef Q_OS_WIN
|
||||
Qt::HANDLE wmutex;
|
||||
Qt::HANDLE rmutex;
|
||||
@@ -55,6 +61,6 @@ private:
|
||||
|
||||
#endif
|
||||
LockMode m_lock_mode;
|
||||
};
|
||||
};
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
+54
-52
@@ -10,70 +10,72 @@
|
||||
|
||||
bool QtLockedFile::lock(LockMode mode, bool block)
|
||||
{
|
||||
if (!isOpen()) {
|
||||
qWarning("QtLockedFile::lock(): file is not opened");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode == NoLock)
|
||||
return unlock();
|
||||
|
||||
if (mode == m_lock_mode)
|
||||
return true;
|
||||
if (!isOpen())
|
||||
{
|
||||
qWarning("QtLockedFile::lock(): file is not opened");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_lock_mode != NoLock)
|
||||
unlock();
|
||||
if (mode == NoLock)
|
||||
return unlock();
|
||||
|
||||
struct flock fl;
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK;
|
||||
int cmd = block ? F_SETLKW : F_SETLK;
|
||||
int ret = fcntl(handle(), cmd, &fl);
|
||||
|
||||
if (ret == -1) {
|
||||
if (errno != EINTR && errno != EAGAIN)
|
||||
qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
m_lock_mode = mode;
|
||||
if (mode == m_lock_mode)
|
||||
return true;
|
||||
|
||||
if (m_lock_mode != NoLock)
|
||||
unlock();
|
||||
|
||||
struct flock fl;
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK;
|
||||
int cmd = block ? F_SETLKW : F_SETLK;
|
||||
int ret = fcntl(handle(), cmd, &fl);
|
||||
|
||||
if (ret == -1)
|
||||
{
|
||||
if (errno != EINTR && errno != EAGAIN)
|
||||
qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
m_lock_mode = mode;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool QtLockedFile::unlock()
|
||||
{
|
||||
if (!isOpen()) {
|
||||
qWarning("QtLockedFile::unlock(): file is not opened");
|
||||
return false;
|
||||
}
|
||||
if (!isOpen())
|
||||
{
|
||||
qWarning("QtLockedFile::unlock(): file is not opened");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isLocked())
|
||||
return true;
|
||||
|
||||
struct flock fl;
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_type = F_UNLCK;
|
||||
int ret = fcntl(handle(), F_SETLKW, &fl);
|
||||
|
||||
if (ret == -1) {
|
||||
qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_lock_mode = NoLock;
|
||||
if (!isLocked())
|
||||
return true;
|
||||
|
||||
struct flock fl;
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_type = F_UNLCK;
|
||||
int ret = fcntl(handle(), F_SETLKW, &fl);
|
||||
|
||||
if (ret == -1)
|
||||
{
|
||||
qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_lock_mode = NoLock;
|
||||
return true;
|
||||
}
|
||||
|
||||
QtLockedFile::~QtLockedFile()
|
||||
{
|
||||
if (isOpen())
|
||||
unlock();
|
||||
if (isOpen())
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+144
-127
@@ -16,160 +16,177 @@
|
||||
|
||||
Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate)
|
||||
{
|
||||
if (mutexname.isEmpty()) {
|
||||
QFileInfo fi(*this);
|
||||
mutexname = QString::fromLatin1(MUTEX_PREFIX)
|
||||
+ fi.absoluteFilePath().toLower();
|
||||
}
|
||||
QString mname(mutexname);
|
||||
if (idx >= 0)
|
||||
mname += QString::number(idx);
|
||||
if (mutexname.isEmpty())
|
||||
{
|
||||
QFileInfo fi(*this);
|
||||
mutexname = QString::fromLatin1(MUTEX_PREFIX) + fi.absoluteFilePath().toLower();
|
||||
}
|
||||
QString mname(mutexname);
|
||||
if (idx >= 0)
|
||||
mname += QString::number(idx);
|
||||
|
||||
Qt::HANDLE mutex;
|
||||
if (doCreate) {
|
||||
QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); },
|
||||
{ mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } );
|
||||
if (!mutex) {
|
||||
qErrnoWarning("QtLockedFile::lock(): CreateMutex failed");
|
||||
return 0;
|
||||
}
|
||||
Qt::HANDLE mutex;
|
||||
if (doCreate)
|
||||
{
|
||||
QT_WA({ mutex = CreateMutexW(NULL, FALSE, (TCHAR *)mname.utf16()); }, { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); });
|
||||
if (!mutex)
|
||||
{
|
||||
qErrnoWarning("QtLockedFile::lock(): CreateMutex failed");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); },
|
||||
{ mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } );
|
||||
if (!mutex) {
|
||||
if (GetLastError() != ERROR_FILE_NOT_FOUND)
|
||||
qErrnoWarning("QtLockedFile::lock(): OpenMutex failed");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QT_WA(
|
||||
{ mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR *)mname.utf16()); },
|
||||
{ mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); });
|
||||
if (!mutex)
|
||||
{
|
||||
if (GetLastError() != ERROR_FILE_NOT_FOUND)
|
||||
qErrnoWarning("QtLockedFile::lock(): OpenMutex failed");
|
||||
return 0;
|
||||
}
|
||||
return mutex;
|
||||
}
|
||||
return mutex;
|
||||
}
|
||||
|
||||
bool QtLockedFile::waitMutex(Qt::HANDLE mutex, bool doBlock)
|
||||
{
|
||||
Q_ASSERT(mutex);
|
||||
DWORD res = WaitForSingleObject(mutex, doBlock ? INFINITE : 0);
|
||||
switch (res) {
|
||||
Q_ASSERT(mutex);
|
||||
DWORD res = WaitForSingleObject(mutex, doBlock ? INFINITE : 0);
|
||||
switch (res)
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
case WAIT_ABANDONED:
|
||||
return true;
|
||||
break;
|
||||
return true;
|
||||
break;
|
||||
case WAIT_TIMEOUT:
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
qErrnoWarning("QtLockedFile::lock(): WaitForSingleObject failed");
|
||||
}
|
||||
return false;
|
||||
qErrnoWarning("QtLockedFile::lock(): WaitForSingleObject failed");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool QtLockedFile::lock(LockMode mode, bool block)
|
||||
{
|
||||
if (!isOpen()) {
|
||||
qWarning("QtLockedFile::lock(): file is not opened");
|
||||
return false;
|
||||
}
|
||||
if (!isOpen())
|
||||
{
|
||||
qWarning("QtLockedFile::lock(): file is not opened");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode == NoLock)
|
||||
return unlock();
|
||||
if (mode == NoLock)
|
||||
return unlock();
|
||||
|
||||
if (mode == m_lock_mode)
|
||||
return true;
|
||||
|
||||
if (m_lock_mode != NoLock)
|
||||
unlock();
|
||||
|
||||
if (!wmutex && !(wmutex = getMutexHandle(-1, true)))
|
||||
return false;
|
||||
|
||||
if (!waitMutex(wmutex, block))
|
||||
return false;
|
||||
|
||||
if (mode == ReadLock) {
|
||||
int idx = 0;
|
||||
for (; idx < MAX_READERS; idx++) {
|
||||
rmutex = getMutexHandle(idx, false);
|
||||
if (!rmutex || waitMutex(rmutex, false))
|
||||
break;
|
||||
CloseHandle(rmutex);
|
||||
}
|
||||
bool ok = true;
|
||||
if (idx >= MAX_READERS) {
|
||||
qWarning("QtLockedFile::lock(): too many readers");
|
||||
rmutex = 0;
|
||||
ok = false;
|
||||
}
|
||||
else if (!rmutex) {
|
||||
rmutex = getMutexHandle(idx, true);
|
||||
if (!rmutex || !waitMutex(rmutex, false))
|
||||
ok = false;
|
||||
}
|
||||
if (!ok && rmutex) {
|
||||
CloseHandle(rmutex);
|
||||
rmutex = 0;
|
||||
}
|
||||
ReleaseMutex(wmutex);
|
||||
if (!ok)
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
Q_ASSERT(rmutexes.isEmpty());
|
||||
for (int i = 0; i < MAX_READERS; i++) {
|
||||
Qt::HANDLE mutex = getMutexHandle(i, false);
|
||||
if (mutex)
|
||||
rmutexes.append(mutex);
|
||||
}
|
||||
if (rmutexes.size()) {
|
||||
DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(),
|
||||
TRUE, block ? INFINITE : 0);
|
||||
if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED) {
|
||||
if (res != WAIT_TIMEOUT)
|
||||
qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed");
|
||||
m_lock_mode = WriteLock;
|
||||
unlock();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_lock_mode = mode;
|
||||
if (mode == m_lock_mode)
|
||||
return true;
|
||||
|
||||
if (m_lock_mode != NoLock)
|
||||
unlock();
|
||||
|
||||
if (!wmutex && !(wmutex = getMutexHandle(-1, true)))
|
||||
return false;
|
||||
|
||||
if (!waitMutex(wmutex, block))
|
||||
return false;
|
||||
|
||||
if (mode == ReadLock)
|
||||
{
|
||||
int idx = 0;
|
||||
for (; idx < MAX_READERS; idx++)
|
||||
{
|
||||
rmutex = getMutexHandle(idx, false);
|
||||
if (!rmutex || waitMutex(rmutex, false))
|
||||
break;
|
||||
CloseHandle(rmutex);
|
||||
}
|
||||
bool ok = true;
|
||||
if (idx >= MAX_READERS)
|
||||
{
|
||||
qWarning("QtLockedFile::lock(): too many readers");
|
||||
rmutex = 0;
|
||||
ok = false;
|
||||
}
|
||||
else if (!rmutex)
|
||||
{
|
||||
rmutex = getMutexHandle(idx, true);
|
||||
if (!rmutex || !waitMutex(rmutex, false))
|
||||
ok = false;
|
||||
}
|
||||
if (!ok && rmutex)
|
||||
{
|
||||
CloseHandle(rmutex);
|
||||
rmutex = 0;
|
||||
}
|
||||
ReleaseMutex(wmutex);
|
||||
if (!ok)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_ASSERT(rmutexes.isEmpty());
|
||||
for (int i = 0; i < MAX_READERS; i++)
|
||||
{
|
||||
Qt::HANDLE mutex = getMutexHandle(i, false);
|
||||
if (mutex)
|
||||
rmutexes.append(mutex);
|
||||
}
|
||||
if (rmutexes.size())
|
||||
{
|
||||
DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(), TRUE, block ? INFINITE : 0);
|
||||
if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED)
|
||||
{
|
||||
if (res != WAIT_TIMEOUT)
|
||||
qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed");
|
||||
m_lock_mode = WriteLock;
|
||||
unlock();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_lock_mode = mode;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QtLockedFile::unlock()
|
||||
{
|
||||
if (!isOpen()) {
|
||||
qWarning("QtLockedFile::unlock(): file is not opened");
|
||||
return false;
|
||||
}
|
||||
if (!isOpen())
|
||||
{
|
||||
qWarning("QtLockedFile::unlock(): file is not opened");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isLocked())
|
||||
return true;
|
||||
|
||||
if (m_lock_mode == ReadLock) {
|
||||
ReleaseMutex(rmutex);
|
||||
CloseHandle(rmutex);
|
||||
rmutex = 0;
|
||||
}
|
||||
else {
|
||||
for (Qt::HANDLE mutex : std::as_const(rmutexes)) {
|
||||
ReleaseMutex(mutex);
|
||||
CloseHandle(mutex);
|
||||
}
|
||||
rmutexes.clear();
|
||||
ReleaseMutex(wmutex);
|
||||
}
|
||||
|
||||
m_lock_mode = QtLockedFile::NoLock;
|
||||
if (!isLocked())
|
||||
return true;
|
||||
|
||||
if (m_lock_mode == ReadLock)
|
||||
{
|
||||
ReleaseMutex(rmutex);
|
||||
CloseHandle(rmutex);
|
||||
rmutex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Qt::HANDLE mutex : std::as_const(rmutexes))
|
||||
{
|
||||
ReleaseMutex(mutex);
|
||||
CloseHandle(mutex);
|
||||
}
|
||||
rmutexes.clear();
|
||||
ReleaseMutex(wmutex);
|
||||
}
|
||||
|
||||
m_lock_mode = QtLockedFile::NoLock;
|
||||
return true;
|
||||
}
|
||||
|
||||
QtLockedFile::~QtLockedFile()
|
||||
{
|
||||
if (isOpen())
|
||||
unlock();
|
||||
if (wmutex)
|
||||
CloseHandle(wmutex);
|
||||
if (isOpen())
|
||||
unlock();
|
||||
if (wmutex)
|
||||
CloseHandle(wmutex);
|
||||
}
|
||||
Executable → Regular
+23
-31
@@ -1,7 +1,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include "qtsingleapplication.h"
|
||||
#include "qtlocalpeer.h"
|
||||
|
||||
@@ -12,10 +11,10 @@
|
||||
void QtSingleApplication::sysInit(const QString &appId)
|
||||
{
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
actWin = nullptr;
|
||||
actWin = nullptr;
|
||||
#endif
|
||||
peer = new QtLocalPeer(this, appId);
|
||||
connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::messageReceived);
|
||||
peer = new QtLocalPeer(this, appId);
|
||||
connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::messageReceived);
|
||||
}
|
||||
|
||||
QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled)
|
||||
@@ -26,9 +25,9 @@ QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled
|
||||
#endif
|
||||
{
|
||||
#ifndef QT6_GUI_AVAILABLE
|
||||
Q_UNUSED(GUIenabled);
|
||||
Q_UNUSED(GUIenabled);
|
||||
#endif
|
||||
sysInit();
|
||||
sysInit();
|
||||
}
|
||||
|
||||
QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv)
|
||||
@@ -38,53 +37,46 @@ QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char *
|
||||
: QCoreApplication(argc, argv)
|
||||
#endif
|
||||
{
|
||||
sysInit(appId);
|
||||
sysInit(appId);
|
||||
}
|
||||
|
||||
bool QtSingleApplication::isRunning()
|
||||
{
|
||||
return peer->isClient();
|
||||
return peer->isClient();
|
||||
}
|
||||
|
||||
bool QtSingleApplication::sendMessage(const QString &message, int timeout)
|
||||
{
|
||||
return peer->sendMessage(message, timeout);
|
||||
return peer->sendMessage(message, timeout);
|
||||
}
|
||||
|
||||
QString QtSingleApplication::id() const
|
||||
{
|
||||
return peer->applicationId();
|
||||
return peer->applicationId();
|
||||
}
|
||||
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage)
|
||||
void QtSingleApplication::setActivationWindow(QWidget *aw, bool activateOnMessage)
|
||||
{
|
||||
actWin = aw;
|
||||
if (activateOnMessage)
|
||||
connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow);
|
||||
else
|
||||
disconnect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow);
|
||||
actWin = aw;
|
||||
if (activateOnMessage)
|
||||
connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow);
|
||||
else
|
||||
disconnect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow);
|
||||
}
|
||||
|
||||
QWidget* QtSingleApplication::activationWindow() const
|
||||
QWidget *QtSingleApplication::activationWindow() const
|
||||
{
|
||||
return actWin;
|
||||
return actWin;
|
||||
}
|
||||
|
||||
void QtSingleApplication::activateWindow()
|
||||
{
|
||||
if (actWin) {
|
||||
actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
|
||||
actWin->raise();
|
||||
actWin->activateWindow();
|
||||
}
|
||||
if (actWin)
|
||||
{
|
||||
actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
|
||||
actWin->raise();
|
||||
actWin->activateWindow();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+29
-26
@@ -15,53 +15,56 @@
|
||||
class QtLocalPeer;
|
||||
|
||||
#ifndef QTSINGLEAPPLICATION_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define QTSINGLEAPPLICATION_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_QTSINGLEAPPLICATION_LIB)
|
||||
# define QTSINGLEAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QTSINGLEAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define QTSINGLEAPPLICATION_EXPORT
|
||||
#else
|
||||
#if defined(MAKE_QTSINGLEAPPLICATION_LIB)
|
||||
#define QTSINGLEAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define QTSINGLEAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QTSINGLEAPPLICATION_BASE
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtSingleApplication(int &argc, char **argv, bool GUIenabled = true);
|
||||
QtSingleApplication(const QString &appId, int &argc, char **argv);
|
||||
QtSingleApplication(int &argc, char **argv, bool GUIenabled = true);
|
||||
QtSingleApplication(const QString &appId, int &argc, char **argv);
|
||||
|
||||
bool isRunning();
|
||||
QString id() const;
|
||||
bool isRunning();
|
||||
QString id() const;
|
||||
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
void setActivationWindow(QWidget* aw, bool activateOnMessage = true);
|
||||
QWidget* activationWindow() const;
|
||||
void setActivationWindow(QWidget *aw, bool activateOnMessage = true);
|
||||
QWidget *activationWindow() const;
|
||||
#endif
|
||||
|
||||
void initialize(bool dummy = true)
|
||||
{ isRunning(); Q_UNUSED(dummy) }
|
||||
|
||||
void initialize(bool dummy = true)
|
||||
{
|
||||
isRunning();
|
||||
Q_UNUSED(dummy)
|
||||
}
|
||||
|
||||
public Q_SLOTS:
|
||||
bool sendMessage(const QString &message, int timeout = 5000);
|
||||
bool sendMessage(const QString &message, int timeout = 5000);
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
void activateWindow();
|
||||
void activateWindow();
|
||||
#endif
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
void messageReceived(const QString &message);
|
||||
void messageReceived(const QString &message);
|
||||
|
||||
|
||||
private:
|
||||
void sysInit(const QString &appId = QString());
|
||||
QtLocalPeer *peer;
|
||||
void sysInit(const QString &appId = QString());
|
||||
QtLocalPeer *peer;
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
QWidget *actWin;
|
||||
QWidget *actWin;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+7
-28
@@ -1,60 +1,39 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include "qtsinglecoreapplication.h"
|
||||
#include "qtlocalpeer.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QtSingleCoreApplication::QtSingleCoreApplication(int &argc, char **argv)
|
||||
: QCoreApplication(argc, argv)
|
||||
{
|
||||
peer = new QtLocalPeer(this);
|
||||
connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleCoreApplication::messageReceived);
|
||||
peer = new QtLocalPeer(this);
|
||||
connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleCoreApplication::messageReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QtSingleCoreApplication::QtSingleCoreApplication(const QString &appId, int &argc, char **argv)
|
||||
: QCoreApplication(argc, argv)
|
||||
{
|
||||
peer = new QtLocalPeer(this, appId);
|
||||
connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleCoreApplication::messageReceived);
|
||||
peer = new QtLocalPeer(this, appId);
|
||||
connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleCoreApplication::messageReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool QtSingleCoreApplication::isRunning()
|
||||
{
|
||||
return peer->isClient();
|
||||
return peer->isClient();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool QtSingleCoreApplication::sendMessage(const QString &message, int timeout)
|
||||
{
|
||||
return peer->sendMessage(message, timeout);
|
||||
return peer->sendMessage(message, timeout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QString QtSingleCoreApplication::id() const
|
||||
{
|
||||
return peer->applicationId();
|
||||
return peer->applicationId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+18
-18
@@ -9,38 +9,38 @@
|
||||
class QtLocalPeer;
|
||||
|
||||
#ifndef QTSINGLECOREAPPLICATION_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define QTSINGLEAPPLICATION_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_QTSINGLECOREAPPLICATION_LIB)
|
||||
# define QTSINGLECOREAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QTSINGLECOREAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define QTSINGLEAPPLICATION_EXPORT
|
||||
#else
|
||||
#if defined(MAKE_QTSINGLECOREAPPLICATION_LIB)
|
||||
#define QTSINGLECOREAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define QTSINGLECOREAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class QTSINGLECOREAPPLICATION_EXPORT QtSingleCoreApplication : public QCoreApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtSingleCoreApplication(int &argc, char **argv);
|
||||
QtSingleCoreApplication(const QString &appId, int &argc, char **argv);
|
||||
QtSingleCoreApplication(int &argc, char **argv);
|
||||
QtSingleCoreApplication(const QString &appId, int &argc, char **argv);
|
||||
|
||||
bool isRunning();
|
||||
QString id() const;
|
||||
bool isRunning();
|
||||
QString id() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
bool sendMessage(const QString &message, int timeout = 5000);
|
||||
bool sendMessage(const QString &message, int timeout = 5000);
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
void messageReceived(const QString &message);
|
||||
void messageReceived(const QString &message);
|
||||
|
||||
|
||||
private:
|
||||
QtLocalPeer* peer;
|
||||
QtLocalPeer *peer;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+9
-10
@@ -5,16 +5,15 @@
|
||||
|
||||
namespace WmsJson
|
||||
{
|
||||
class IECC2WMS
|
||||
{
|
||||
class IECC2WMS
|
||||
{
|
||||
|
||||
public:
|
||||
IECC2WMS() = default;
|
||||
virtual ~IECC2WMS() = default;
|
||||
public:
|
||||
IECC2WMS() = default;
|
||||
virtual ~IECC2WMS() = default;
|
||||
|
||||
|
||||
virtual void playerChanged(int playerId, int exerciseId) = 0;
|
||||
virtual void exerciseDataChanged(int exerciseId, int betrZustand) = 0;
|
||||
|
||||
};
|
||||
}
|
||||
virtual void playerChanged(int playerId, int exerciseId) = 0;
|
||||
virtual void exerciseDataChanged(int exerciseId, int betrZustand) = 0;
|
||||
};
|
||||
}
|
||||
Executable → Regular
+20
-16
@@ -18,7 +18,7 @@ public:
|
||||
{
|
||||
RegistrationOk = 0,
|
||||
PlayerNotFound = 1,
|
||||
PlayerDeleted = 2,
|
||||
PlayerDeleted = 2,
|
||||
AssignmentIncorrect = 3,
|
||||
EquipNoAlreadyAssigned = 4,
|
||||
RegistrationFailed = 5
|
||||
@@ -34,8 +34,8 @@ public:
|
||||
enum PlayerState
|
||||
{
|
||||
NOT_FOUND = 0,
|
||||
FOUND = 1,
|
||||
DELETED = 2
|
||||
FOUND = 1,
|
||||
DELETED = 2
|
||||
};
|
||||
|
||||
enum PlayerAssignState
|
||||
@@ -51,16 +51,16 @@ public:
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case UNDEFINED:
|
||||
case NOT_ASSIGNED:
|
||||
case ASSIGNED:
|
||||
case HANDOUT_EXCON:
|
||||
case HANDOUT_WMS:
|
||||
case HANDOUT_EXCON_OVERRULED_WMS:
|
||||
return static_cast<PlayerAssignState>(s);
|
||||
case UNDEFINED:
|
||||
case NOT_ASSIGNED:
|
||||
case ASSIGNED:
|
||||
case HANDOUT_EXCON:
|
||||
case HANDOUT_WMS:
|
||||
case HANDOUT_EXCON_OVERRULED_WMS:
|
||||
return static_cast<PlayerAssignState>(s);
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return UNDEFINED;
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
struct PlayerInfo
|
||||
@@ -104,15 +104,19 @@ public:
|
||||
int specialType = 0;
|
||||
int minEquipNo = 0;
|
||||
int maxEquipNo = 0;
|
||||
int taVulnerabilityModelId = 0;
|
||||
int taVulnerabilityModelId = 0;
|
||||
int taPlayerTypeId = 0;
|
||||
bool deletedInWMS = false;
|
||||
};
|
||||
using equipTypeMap = QMap<int, EquipmentType>;
|
||||
|
||||
|
||||
virtual RegisterReturnValue registerPlayer(int playerId, int equipNo, const PlayerAssignState &zuordnung, const QString &alias,
|
||||
const QString &info, int exerciseId) = 0;
|
||||
|
||||
virtual RegisterReturnValue registerPlayer(int playerId,
|
||||
int equipNo,
|
||||
const PlayerAssignState &zuordnung,
|
||||
const QString &alias,
|
||||
const QString &info,
|
||||
int exerciseId) = 0;
|
||||
|
||||
virtual UnregisterReturnValue unregister(int equipNo, int exerciseId) = 0;
|
||||
virtual PlayerInfo getPlayerInfo(int playerId, int exerciseId) = 0;
|
||||
@@ -120,7 +124,7 @@ public:
|
||||
virtual exerciseMap getExercises() const = 0;
|
||||
virtual Exercise getActualExercise() const = 0;
|
||||
|
||||
|
||||
|
||||
virtual QMap<int, int> getEquipRequirements(int exerciseId) const = 0;
|
||||
|
||||
virtual QMap<int, PlayerInfo> getAllPlayers(int exerciseId) const = 0;
|
||||
|
||||
Executable → Regular
+60
-19
@@ -8,45 +8,86 @@ namespace WebSocketInterface
|
||||
{
|
||||
|
||||
|
||||
namespace JsonKeys
|
||||
{
|
||||
namespace JsonKeys
|
||||
{
|
||||
|
||||
inline QString EXERCISE_ID() { return QStringLiteral("exerciseId"); }
|
||||
inline QString DATA_MODIFICATION() { return QStringLiteral("dataModification"); }
|
||||
inline QString PARTICIPANT_ID() { return QStringLiteral("participantId"); }
|
||||
inline QString REGISTRATION_RETURN_VALUE() { return QStringLiteral("registrationReturnValue"); }
|
||||
inline QString EXERCISE_ID()
|
||||
{
|
||||
return QStringLiteral("exerciseId");
|
||||
}
|
||||
inline QString DATA_MODIFICATION()
|
||||
{
|
||||
return QStringLiteral("dataModification");
|
||||
}
|
||||
inline QString PARTICIPANT_ID()
|
||||
{
|
||||
return QStringLiteral("participantId");
|
||||
}
|
||||
inline QString REGISTRATION_RETURN_VALUE()
|
||||
{
|
||||
return QStringLiteral("registrationReturnValue");
|
||||
}
|
||||
|
||||
|
||||
inline QString EQUIPMENT_TYPES_REQUEST() { return QStringLiteral("equipmentTypesRequest"); }
|
||||
inline QString EQUIPMENT_TYPES_REQUEST()
|
||||
{
|
||||
return QStringLiteral("equipmentTypesRequest");
|
||||
}
|
||||
|
||||
|
||||
inline QString EQUIPMENT_TYPES_REPLY() { return QStringLiteral("equipmentTypesReply"); }
|
||||
inline QString EQUIPMENT_TYPES_REPLY()
|
||||
{
|
||||
return QStringLiteral("equipmentTypesReply");
|
||||
}
|
||||
|
||||
|
||||
inline QString EXERCISES_REQUEST() { return QStringLiteral("exercisesRequest"); }
|
||||
inline QString EXERCISES_REQUEST()
|
||||
{
|
||||
return QStringLiteral("exercisesRequest");
|
||||
}
|
||||
|
||||
|
||||
inline QString EXERCISES_REPLY() { return QStringLiteral("exercisesReply"); }
|
||||
inline QString EXERCISES_REPLY()
|
||||
{
|
||||
return QStringLiteral("exercisesReply");
|
||||
}
|
||||
|
||||
|
||||
inline QString EXERCISE_UPDATE() { return QStringLiteral("exercisesUpdate"); }
|
||||
inline QString EXERCISE_UPDATE()
|
||||
{
|
||||
return QStringLiteral("exercisesUpdate");
|
||||
}
|
||||
|
||||
|
||||
inline QString PARTICIPANTS_REQUEST() { return QStringLiteral("participantsRequest"); }
|
||||
inline QString PARTICIPANTS_REQUEST()
|
||||
{
|
||||
return QStringLiteral("participantsRequest");
|
||||
}
|
||||
|
||||
|
||||
inline QString PARTICIPANTS_REPLY() { return QStringLiteral("participantsReply"); }
|
||||
inline QString PARTICIPANTS_REPLY()
|
||||
{
|
||||
return QStringLiteral("participantsReply");
|
||||
}
|
||||
|
||||
|
||||
inline QString PARTICIPANTS_UPDATE() { return QStringLiteral("participantsUpdate"); }
|
||||
inline QString PARTICIPANTS_UPDATE()
|
||||
{
|
||||
return QStringLiteral("participantsUpdate");
|
||||
}
|
||||
|
||||
|
||||
inline QString PARTICIPANT_REGISTER_IN_EXCON_REQUEST() { return QStringLiteral("participantRegisterInEXCONRequest");}
|
||||
inline QString PARTICIPANT_REGISTER_IN_EXCON_REQUEST()
|
||||
{
|
||||
return QStringLiteral("participantRegisterInEXCONRequest");
|
||||
}
|
||||
|
||||
|
||||
inline QString PARTICIPANT_REGISTER_IN_EXCON_REPLY() { return QStringLiteral("participantRegisterInEXCONReply");}
|
||||
inline QString PARTICIPANT_REGISTER_IN_EXCON_REPLY()
|
||||
{
|
||||
return QStringLiteral("participantRegisterInEXCONReply");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable → Regular
+5
-5
@@ -17,8 +17,8 @@ QJsonObject EquipRequirements::toJson() const
|
||||
}
|
||||
|
||||
QJsonObject retMap;
|
||||
retMap[QLatin1String("equipMap")] = arr;
|
||||
retMap[QLatin1String("ok")] = m_ok;
|
||||
retMap[QLatin1String("equipMap")] = arr;
|
||||
retMap[QLatin1String("ok")] = m_ok;
|
||||
|
||||
return retMap;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ EquipRequirements EquipRequirements::fromJson(const QJsonObject &map)
|
||||
{
|
||||
const QJsonObject obj = ele.toObject();
|
||||
int equipmentTypeId = obj[QLatin1String("key")].toInt();
|
||||
int amount = obj[QLatin1String("value")].toInt();
|
||||
int amount = obj[QLatin1String("value")].toInt();
|
||||
eq.m_equipRequire.insert(equipmentTypeId, amount);
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ QVariantMap EquipRequirements::toVariantMap() const
|
||||
viMap.insert(QString::number(it.key()), QVariant(it.value()));
|
||||
|
||||
QVariantMap retMap;
|
||||
retMap[QLatin1String("equipMap")] = QVariant(viMap);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
retMap[QLatin1String("equipMap")] = QVariant(viMap);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return retMap;
|
||||
}
|
||||
|
||||
Executable → Regular
+2
-2
@@ -17,7 +17,7 @@ public:
|
||||
QVariantMap toVariantMap() const;
|
||||
static EquipRequirements fromVariantMap(const QVariantMap &map);
|
||||
|
||||
|
||||
|
||||
QMap<int, int> getEquipRequirements() const { return m_equipRequire; }
|
||||
bool getOk() const { return m_ok; }
|
||||
|
||||
@@ -26,5 +26,5 @@ public:
|
||||
|
||||
private:
|
||||
QMap<int, int> m_equipRequire;
|
||||
bool m_ok = false;
|
||||
bool m_ok = false;
|
||||
};
|
||||
Executable → Regular
+32
-32
@@ -8,14 +8,14 @@ QJsonObject EquipmentTypes::toJson(const IWMS2ECC::EquipmentType &et)
|
||||
{
|
||||
QJsonObject obj;
|
||||
|
||||
obj[QLatin1String("id")] = et.id;
|
||||
obj[QLatin1String("name")] = et.name;
|
||||
obj[QLatin1String("minEquipNo")] = et.minEquipNo;
|
||||
obj[QLatin1String("maxEquipNo")] = et.maxEquipNo;
|
||||
obj[QLatin1String("specialType")] = et.specialType;
|
||||
obj[QLatin1String("id")] = et.id;
|
||||
obj[QLatin1String("name")] = et.name;
|
||||
obj[QLatin1String("minEquipNo")] = et.minEquipNo;
|
||||
obj[QLatin1String("maxEquipNo")] = et.maxEquipNo;
|
||||
obj[QLatin1String("specialType")] = et.specialType;
|
||||
obj[QLatin1String("taVulnerabilityModelId")] = et.taVulnerabilityModelId;
|
||||
obj[QLatin1String("taPlayerTypeId")] = et.taPlayerTypeId;
|
||||
obj[QLatin1String("deletedInWMS")] = et.deletedInWMS;
|
||||
obj[QLatin1String("taPlayerTypeId")] = et.taPlayerTypeId;
|
||||
obj[QLatin1String("deletedInWMS")] = et.deletedInWMS;
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -24,14 +24,14 @@ IWMS2ECC::EquipmentType EquipmentTypes::fromJson(const QJsonObject &obj)
|
||||
{
|
||||
IWMS2ECC::EquipmentType et;
|
||||
|
||||
et.id = obj[QLatin1String("id")].toInt();
|
||||
et.name = obj[QLatin1String("name")].toString();
|
||||
et.minEquipNo = obj[QLatin1String("minEquipNo")].toInt();
|
||||
et.maxEquipNo = obj[QLatin1String("maxEquipNo")].toInt();
|
||||
et.specialType = obj[QLatin1String("specialType")].toInt();
|
||||
et.id = obj[QLatin1String("id")].toInt();
|
||||
et.name = obj[QLatin1String("name")].toString();
|
||||
et.minEquipNo = obj[QLatin1String("minEquipNo")].toInt();
|
||||
et.maxEquipNo = obj[QLatin1String("maxEquipNo")].toInt();
|
||||
et.specialType = obj[QLatin1String("specialType")].toInt();
|
||||
et.taVulnerabilityModelId = obj[QLatin1String("taVulnerabilityModelId")].toInt();
|
||||
et.taPlayerTypeId = obj[QLatin1String("taPlayerTypeId")].toInt();
|
||||
et.deletedInWMS = obj[QLatin1String("deletedInWMS")].toBool();
|
||||
et.taPlayerTypeId = obj[QLatin1String("taPlayerTypeId")].toInt();
|
||||
et.deletedInWMS = obj[QLatin1String("deletedInWMS")].toBool();
|
||||
|
||||
return et;
|
||||
}
|
||||
@@ -43,8 +43,8 @@ QJsonObject EquipmentTypes::toJsonAll() const
|
||||
arr.append(toJson(et));
|
||||
|
||||
QJsonObject retMap;
|
||||
retMap[QLatin1String("etMap")] = arr;
|
||||
retMap[QLatin1String("ok")] = m_ok;
|
||||
retMap[QLatin1String("etMap")] = arr;
|
||||
retMap[QLatin1String("ok")] = m_ok;
|
||||
|
||||
return retMap;
|
||||
}
|
||||
@@ -70,14 +70,14 @@ QVariantMap EquipmentTypes::toVariantMap() const
|
||||
{
|
||||
QVariantMap vMap;
|
||||
|
||||
vMap[QLatin1String("id")] = QVariant(m_equipmentType.id);
|
||||
vMap[QLatin1String("name")] = m_equipmentType.name;
|
||||
vMap[QLatin1String("minEquipNo")] = QVariant((int)m_equipmentType.minEquipNo);
|
||||
vMap[QLatin1String("maxEquipNo")] = QVariant((int)m_equipmentType.maxEquipNo);
|
||||
vMap[QLatin1String("specialType")] = QVariant(m_equipmentType.specialType);
|
||||
vMap[QLatin1String("deletedInWMS")] = QVariant(m_equipmentType.deletedInWMS);
|
||||
vMap[QLatin1String("id")] = QVariant(m_equipmentType.id);
|
||||
vMap[QLatin1String("name")] = m_equipmentType.name;
|
||||
vMap[QLatin1String("minEquipNo")] = QVariant((int)m_equipmentType.minEquipNo);
|
||||
vMap[QLatin1String("maxEquipNo")] = QVariant((int)m_equipmentType.maxEquipNo);
|
||||
vMap[QLatin1String("specialType")] = QVariant(m_equipmentType.specialType);
|
||||
vMap[QLatin1String("deletedInWMS")] = QVariant(m_equipmentType.deletedInWMS);
|
||||
|
||||
vMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
vMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return vMap;
|
||||
}
|
||||
@@ -86,12 +86,12 @@ EquipmentTypes EquipmentTypes::fromVariantMap(const QVariantMap &map)
|
||||
{
|
||||
EquipmentTypes ets;
|
||||
|
||||
ets.m_equipmentType.id = map[QLatin1String("id")].toInt();
|
||||
ets.m_equipmentType.name = map[QLatin1String("name")].toString();
|
||||
ets.m_equipmentType.minEquipNo = map[QLatin1String("minEquipNo")].toInt();
|
||||
ets.m_equipmentType.maxEquipNo = map[QLatin1String("maxEquipNo")].toInt();
|
||||
ets.m_equipmentType.specialType = map[QLatin1String("specialType")].toInt();
|
||||
ets.m_equipmentType.deletedInWMS = map[QLatin1String("deletedInWMS")].toBool();
|
||||
ets.m_equipmentType.id = map[QLatin1String("id")].toInt();
|
||||
ets.m_equipmentType.name = map[QLatin1String("name")].toString();
|
||||
ets.m_equipmentType.minEquipNo = map[QLatin1String("minEquipNo")].toInt();
|
||||
ets.m_equipmentType.maxEquipNo = map[QLatin1String("maxEquipNo")].toInt();
|
||||
ets.m_equipmentType.specialType = map[QLatin1String("specialType")].toInt();
|
||||
ets.m_equipmentType.deletedInWMS = map[QLatin1String("deletedInWMS")].toBool();
|
||||
|
||||
ets.m_ok = map[QLatin1String("ok")].toBool();
|
||||
|
||||
@@ -103,13 +103,13 @@ QVariantMap EquipmentTypes::toVariantMapAll() const
|
||||
QVariantMap vMap;
|
||||
for (IWMS2ECC::equipTypeMap::ConstIterator it = m_equipmentTypes.begin(); it != m_equipmentTypes.end(); ++it)
|
||||
{
|
||||
m_equipmentType = it.value();
|
||||
m_equipmentType = it.value();
|
||||
vMap.insert(QString::number(it.key()), QVariant(toVariantMap()));
|
||||
}
|
||||
|
||||
QVariantMap retMap;
|
||||
retMap[QLatin1String("etMap")] = QVariant(vMap);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
retMap[QLatin1String("etMap")] = QVariant(vMap);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return retMap;
|
||||
}
|
||||
|
||||
Executable → Regular
+3
-3
@@ -31,7 +31,7 @@ public:
|
||||
void setOk(bool ok) { m_ok = ok; }
|
||||
|
||||
private:
|
||||
IWMS2ECC::equipTypeMap m_equipmentTypes;
|
||||
mutable IWMS2ECC::EquipmentType m_equipmentType;
|
||||
bool m_ok = false;
|
||||
IWMS2ECC::equipTypeMap m_equipmentTypes;
|
||||
mutable IWMS2ECC::EquipmentType m_equipmentType;
|
||||
bool m_ok = false;
|
||||
};
|
||||
Executable → Regular
+114
-114
@@ -8,128 +8,128 @@
|
||||
namespace EXCON
|
||||
{
|
||||
|
||||
QJsonObject Exercises::toJson(const IWMS2ECC::Exercise &ex) const
|
||||
{
|
||||
QJsonObject obj;
|
||||
|
||||
obj[QLatin1String("id")] = ex.id;
|
||||
obj[QLatin1String("actExercise")] = ex.actExercise;
|
||||
obj[QLatin1String("start")] = static_cast<qint64>(ex.start);
|
||||
obj[QLatin1String("end")] = static_cast<qint64>(ex.end);
|
||||
obj[QLatin1String("name")] = ex.name;
|
||||
obj[QLatin1String("state")] = ex.stateAsString;
|
||||
|
||||
obj[QLatin1String("ok")] = m_ok;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
IWMS2ECC::Exercise Exercises::fromJson(const QJsonObject &obj)
|
||||
{
|
||||
IWMS2ECC::Exercise ex;
|
||||
|
||||
ex.id = obj[QLatin1String("id")].toInt();
|
||||
ex.actExercise = obj[QLatin1String("actExercise")].toInt();
|
||||
ex.start = static_cast<time_t>(obj[QLatin1String("start")].toInt());
|
||||
ex.end = static_cast<time_t>(obj[QLatin1String("end")].toInt());
|
||||
ex.name = obj[QLatin1String("name")].toString();
|
||||
ex.stateAsString = obj[QLatin1String("state")].toString();
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
QJsonObject Exercises::toJsonAll() const
|
||||
{
|
||||
QJsonArray arr;
|
||||
for (const IWMS2ECC::Exercise &ex : m_exercises)
|
||||
arr.append(toJson(ex));
|
||||
|
||||
QJsonObject obj;
|
||||
obj[QLatin1String("exMap")] = arr;
|
||||
obj[QLatin1String("ok")] = m_ok;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
Exercises Exercises::fromJsonAll(const QJsonObject &map)
|
||||
{
|
||||
Exercises ex;
|
||||
|
||||
const QJsonArray arr = map[QLatin1String("exMap")].toArray();
|
||||
for (const QJsonValue &val : arr)
|
||||
QJsonObject Exercises::toJson(const IWMS2ECC::Exercise &ex) const
|
||||
{
|
||||
const IWMS2ECC::Exercise exinfo = fromJson(val.toObject());
|
||||
ex.m_exercises.insert(exinfo.id, exinfo);
|
||||
QJsonObject obj;
|
||||
|
||||
obj[QLatin1String("id")] = ex.id;
|
||||
obj[QLatin1String("actExercise")] = ex.actExercise;
|
||||
obj[QLatin1String("start")] = static_cast<qint64>(ex.start);
|
||||
obj[QLatin1String("end")] = static_cast<qint64>(ex.end);
|
||||
obj[QLatin1String("name")] = ex.name;
|
||||
obj[QLatin1String("state")] = ex.stateAsString;
|
||||
|
||||
obj[QLatin1String("ok")] = m_ok;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
ex.m_ok = map[QLatin1String("ok")].toBool();
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
|
||||
QVariantMap Exercises::toVariantMap() const
|
||||
{
|
||||
QVariantMap vMap;
|
||||
|
||||
vMap[QLatin1String("id")] = QVariant(m_exercise.id);
|
||||
vMap[QLatin1String("name")] = m_exercise.name;
|
||||
vMap[QLatin1String("start")] = QVariant(static_cast<qint64>(m_exercise.start));
|
||||
vMap[QLatin1String("end")] = QVariant(static_cast<qint64>(m_exercise.end));
|
||||
vMap[QLatin1String("state")] = m_exercise.stateAsString;
|
||||
|
||||
vMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return vMap;
|
||||
}
|
||||
|
||||
Exercises Exercises::fromVariantMap(const QVariantMap &map)
|
||||
{
|
||||
Exercises ex;
|
||||
|
||||
ex.m_exercise.id = map[QLatin1String("id")].toInt();
|
||||
ex.m_exercise.name = map[QLatin1String("name")].toString();
|
||||
ex.m_exercise.start = map[QLatin1String("start")].toLongLong();
|
||||
ex.m_exercise.end = map[QLatin1String("end")].toLongLong();
|
||||
ex.m_exercise.stateAsString = map[QLatin1String("state")].toString();
|
||||
|
||||
ex.m_ok = map[QLatin1String("ok")].toBool();
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
QVariantMap Exercises::toVariantMapAll() const
|
||||
{
|
||||
QVariantMap vMap;
|
||||
for (IWMS2ECC::exerciseMap::ConstIterator it = m_exercises.begin(); it != m_exercises.end(); ++it)
|
||||
IWMS2ECC::Exercise Exercises::fromJson(const QJsonObject &obj)
|
||||
{
|
||||
m_exercise = it.value();
|
||||
vMap.insert(QString::number(it.key()), QVariant(toVariantMap()));
|
||||
IWMS2ECC::Exercise ex;
|
||||
|
||||
ex.id = obj[QLatin1String("id")].toInt();
|
||||
ex.actExercise = obj[QLatin1String("actExercise")].toInt();
|
||||
ex.start = static_cast<time_t>(obj[QLatin1String("start")].toInt());
|
||||
ex.end = static_cast<time_t>(obj[QLatin1String("end")].toInt());
|
||||
ex.name = obj[QLatin1String("name")].toString();
|
||||
ex.stateAsString = obj[QLatin1String("state")].toString();
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
QVariantMap retMap;
|
||||
retMap[QLatin1String("exeMap")] = QVariant(vMap);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return retMap;
|
||||
}
|
||||
|
||||
Exercises Exercises::fromVariantMapAll(const QVariantMap &map)
|
||||
{
|
||||
Exercises ex;
|
||||
|
||||
const QVariantMap vMap = map[QLatin1String("exeMap")].toMap();
|
||||
for (QVariantMap::ConstIterator it = vMap.begin(); it != vMap.end(); ++it)
|
||||
QJsonObject Exercises::toJsonAll() const
|
||||
{
|
||||
|
||||
int key = it.key().toInt();
|
||||
IWMS2ECC::Exercise e = Exercises::fromVariantMap(it.value().toMap()).m_exercise;
|
||||
ex.m_exercises.insert(key, e);
|
||||
QJsonArray arr;
|
||||
for (const IWMS2ECC::Exercise &ex : m_exercises)
|
||||
arr.append(toJson(ex));
|
||||
|
||||
QJsonObject obj;
|
||||
obj[QLatin1String("exMap")] = arr;
|
||||
obj[QLatin1String("ok")] = m_ok;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
ex.m_ok = map[QLatin1String("ok")].toBool();
|
||||
Exercises Exercises::fromJsonAll(const QJsonObject &map)
|
||||
{
|
||||
Exercises ex;
|
||||
|
||||
const QJsonArray arr = map[QLatin1String("exMap")].toArray();
|
||||
for (const QJsonValue &val : arr)
|
||||
{
|
||||
const IWMS2ECC::Exercise exinfo = fromJson(val.toObject());
|
||||
ex.m_exercises.insert(exinfo.id, exinfo);
|
||||
}
|
||||
|
||||
ex.m_ok = map[QLatin1String("ok")].toBool();
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
|
||||
QVariantMap Exercises::toVariantMap() const
|
||||
{
|
||||
QVariantMap vMap;
|
||||
|
||||
vMap[QLatin1String("id")] = QVariant(m_exercise.id);
|
||||
vMap[QLatin1String("name")] = m_exercise.name;
|
||||
vMap[QLatin1String("start")] = QVariant(static_cast<qint64>(m_exercise.start));
|
||||
vMap[QLatin1String("end")] = QVariant(static_cast<qint64>(m_exercise.end));
|
||||
vMap[QLatin1String("state")] = m_exercise.stateAsString;
|
||||
|
||||
vMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return vMap;
|
||||
}
|
||||
|
||||
Exercises Exercises::fromVariantMap(const QVariantMap &map)
|
||||
{
|
||||
Exercises ex;
|
||||
|
||||
ex.m_exercise.id = map[QLatin1String("id")].toInt();
|
||||
ex.m_exercise.name = map[QLatin1String("name")].toString();
|
||||
ex.m_exercise.start = map[QLatin1String("start")].toLongLong();
|
||||
ex.m_exercise.end = map[QLatin1String("end")].toLongLong();
|
||||
ex.m_exercise.stateAsString = map[QLatin1String("state")].toString();
|
||||
|
||||
ex.m_ok = map[QLatin1String("ok")].toBool();
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
QVariantMap Exercises::toVariantMapAll() const
|
||||
{
|
||||
QVariantMap vMap;
|
||||
for (IWMS2ECC::exerciseMap::ConstIterator it = m_exercises.begin(); it != m_exercises.end(); ++it)
|
||||
{
|
||||
m_exercise = it.value();
|
||||
vMap.insert(QString::number(it.key()), QVariant(toVariantMap()));
|
||||
}
|
||||
|
||||
QVariantMap retMap;
|
||||
retMap[QLatin1String("exeMap")] = QVariant(vMap);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return retMap;
|
||||
}
|
||||
|
||||
Exercises Exercises::fromVariantMapAll(const QVariantMap &map)
|
||||
{
|
||||
Exercises ex;
|
||||
|
||||
const QVariantMap vMap = map[QLatin1String("exeMap")].toMap();
|
||||
for (QVariantMap::ConstIterator it = vMap.begin(); it != vMap.end(); ++it)
|
||||
{
|
||||
|
||||
int key = it.key().toInt();
|
||||
IWMS2ECC::Exercise e = Exercises::fromVariantMap(it.value().toMap()).m_exercise;
|
||||
ex.m_exercises.insert(key, e);
|
||||
}
|
||||
|
||||
ex.m_ok = map[QLatin1String("ok")].toBool();
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+22
-22
@@ -11,31 +11,31 @@
|
||||
namespace EXCON
|
||||
{
|
||||
|
||||
class WMS_JSON_DS_EXPORT Exercises : public IBase
|
||||
{
|
||||
public:
|
||||
QJsonObject toJsonAll() const;
|
||||
static Exercises fromJsonAll(const QJsonObject &map);
|
||||
QJsonObject toJson(const IWMS2ECC::Exercise &ex) const;
|
||||
static IWMS2ECC::Exercise fromJson(const QJsonObject &obj);
|
||||
class WMS_JSON_DS_EXPORT Exercises : public IBase
|
||||
{
|
||||
public:
|
||||
QJsonObject toJsonAll() const;
|
||||
static Exercises fromJsonAll(const QJsonObject &map);
|
||||
QJsonObject toJson(const IWMS2ECC::Exercise &ex) const;
|
||||
static IWMS2ECC::Exercise fromJson(const QJsonObject &obj);
|
||||
|
||||
QVariantMap toVariantMapAll() const;
|
||||
static Exercises fromVariantMapAll(const QVariantMap &map);
|
||||
QVariantMap toVariantMap() const;
|
||||
static Exercises fromVariantMap(const QVariantMap &map);
|
||||
QVariantMap toVariantMapAll() const;
|
||||
static Exercises fromVariantMapAll(const QVariantMap &map);
|
||||
QVariantMap toVariantMap() const;
|
||||
static Exercises fromVariantMap(const QVariantMap &map);
|
||||
|
||||
IWMS2ECC::Exercise getExercise() const { return m_exercise; }
|
||||
IWMS2ECC::exerciseMap getExercises() const { return m_exercises; }
|
||||
bool getOk() const { return m_ok; }
|
||||
IWMS2ECC::Exercise getExercise() const { return m_exercise; }
|
||||
IWMS2ECC::exerciseMap getExercises() const { return m_exercises; }
|
||||
bool getOk() const { return m_ok; }
|
||||
|
||||
void setExercise(const IWMS2ECC::Exercise &exe) { m_exercise = exe; }
|
||||
void setExercises(const IWMS2ECC::exerciseMap &exe) { m_exercises = exe; }
|
||||
void setOk(bool ok) { m_ok = ok; }
|
||||
void setExercise(const IWMS2ECC::Exercise &exe) { m_exercise = exe; }
|
||||
void setExercises(const IWMS2ECC::exerciseMap &exe) { m_exercises = exe; }
|
||||
void setOk(bool ok) { m_ok = ok; }
|
||||
|
||||
private:
|
||||
IWMS2ECC::exerciseMap m_exercises;
|
||||
mutable IWMS2ECC::Exercise m_exercise;
|
||||
bool m_ok = false;
|
||||
};
|
||||
private:
|
||||
IWMS2ECC::exerciseMap m_exercises;
|
||||
mutable IWMS2ECC::Exercise m_exercise;
|
||||
bool m_ok = false;
|
||||
};
|
||||
|
||||
}
|
||||
Executable → Regular
-2
@@ -10,6 +10,4 @@ class WMS_JSON_DS_EXPORT IBase
|
||||
public:
|
||||
IBase() = default;
|
||||
virtual ~IBase() = default;
|
||||
|
||||
};
|
||||
|
||||
Executable → Regular
+75
-77
@@ -9,25 +9,25 @@
|
||||
QJsonObject PlayerInfo::toJson(const IWMS2ECC::PlayerInfo &pi)
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj[QLatin1String("playerState")] = pi.playerState;
|
||||
obj[QLatin1String("playerId")] = pi.playerId;
|
||||
obj[QLatin1String("parentPlayerId")] = pi.parentPlayerId;
|
||||
obj[QLatin1String("equipNo")] = pi.equipNo;
|
||||
obj[QLatin1String("assignState")] = pi.assignState;
|
||||
obj[QLatin1String("exerciseId")] = pi.exerciseId;
|
||||
obj[QLatin1String("forceId")] = pi.forceId;
|
||||
obj[QLatin1String("typeId")] = pi.typeId;
|
||||
obj[QLatin1String("isDeleted")] = pi.isDeleted;
|
||||
obj[QLatin1String("equipTypeId")] = pi.equipTypeId;
|
||||
obj[QLatin1String("typeClassId")] = pi.typeClassId;
|
||||
obj[QLatin1String("symbolColor")] = pi.symbolColor;
|
||||
obj[QLatin1String("symbolPNG")] = QString::fromLatin1(pi.symbolPNG.toBase64());
|
||||
obj[QLatin1String("hierarchy")] = pi.hierarchy;
|
||||
obj[QLatin1String("designator")] = pi.designator;
|
||||
obj[QLatin1String("tactIdent")] = pi.tactIdent;
|
||||
obj[QLatin1String("info")] = pi.info;
|
||||
obj[QLatin1String("alias")] = pi.alias;
|
||||
obj[QLatin1String("forceName")] = pi.forceName;
|
||||
obj[QLatin1String("playerState")] = pi.playerState;
|
||||
obj[QLatin1String("playerId")] = pi.playerId;
|
||||
obj[QLatin1String("parentPlayerId")] = pi.parentPlayerId;
|
||||
obj[QLatin1String("equipNo")] = pi.equipNo;
|
||||
obj[QLatin1String("assignState")] = pi.assignState;
|
||||
obj[QLatin1String("exerciseId")] = pi.exerciseId;
|
||||
obj[QLatin1String("forceId")] = pi.forceId;
|
||||
obj[QLatin1String("typeId")] = pi.typeId;
|
||||
obj[QLatin1String("isDeleted")] = pi.isDeleted;
|
||||
obj[QLatin1String("equipTypeId")] = pi.equipTypeId;
|
||||
obj[QLatin1String("typeClassId")] = pi.typeClassId;
|
||||
obj[QLatin1String("symbolColor")] = pi.symbolColor;
|
||||
obj[QLatin1String("symbolPNG")] = QString::fromLatin1(pi.symbolPNG.toBase64());
|
||||
obj[QLatin1String("hierarchy")] = pi.hierarchy;
|
||||
obj[QLatin1String("designator")] = pi.designator;
|
||||
obj[QLatin1String("tactIdent")] = pi.tactIdent;
|
||||
obj[QLatin1String("info")] = pi.info;
|
||||
obj[QLatin1String("alias")] = pi.alias;
|
||||
obj[QLatin1String("forceName")] = pi.forceName;
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -36,25 +36,25 @@ IWMS2ECC::PlayerInfo PlayerInfo::fromJson(const QJsonObject &obj)
|
||||
{
|
||||
IWMS2ECC::PlayerInfo pi;
|
||||
|
||||
pi.playerState = static_cast<IWMS2ECC::PlayerState>(obj[QLatin1String("playerState")].toInt());
|
||||
pi.playerId = obj[QLatin1String("playerId")].toInt();
|
||||
pi.playerState = static_cast<IWMS2ECC::PlayerState>(obj[QLatin1String("playerState")].toInt());
|
||||
pi.playerId = obj[QLatin1String("playerId")].toInt();
|
||||
pi.parentPlayerId = obj[QLatin1String("parentPlayerId")].toInt();
|
||||
pi.equipNo = obj[QLatin1String("equipNo")].toInt();
|
||||
pi.assignState = static_cast<IWMS2ECC::PlayerAssignState>(obj[QLatin1String("assignState")].toInt());
|
||||
pi.exerciseId = obj[QLatin1String("exerciseId")].toInt();
|
||||
pi.forceId = obj[QLatin1String("forceId")].toInt();
|
||||
pi.typeId = obj[QLatin1String("typeId")].toInt();
|
||||
pi.isDeleted = obj[QLatin1String("isDeleted")].toBool();
|
||||
pi.equipTypeId = obj[QLatin1String("equipTypeId")].toInt();
|
||||
pi.typeClassId = obj[QLatin1String("typeClassId")].toInt();
|
||||
pi.symbolColor = obj[QLatin1String("symbolColor")].toInt();
|
||||
pi.symbolPNG = QByteArray::fromBase64(obj[QLatin1String("symbolPNG")].toString().toLatin1());
|
||||
pi.hierarchy = obj[QLatin1String("hierarchy")].toString();
|
||||
pi.designator = obj[QLatin1String("designator")].toString();
|
||||
pi.tactIdent = obj[QLatin1String("tactIdent")].toString();
|
||||
pi.info = obj[QLatin1String("info")].toString();
|
||||
pi.alias = obj[QLatin1String("alias")].toString();
|
||||
pi.forceName = obj[QLatin1String("forceName")].toString();
|
||||
pi.equipNo = obj[QLatin1String("equipNo")].toInt();
|
||||
pi.assignState = static_cast<IWMS2ECC::PlayerAssignState>(obj[QLatin1String("assignState")].toInt());
|
||||
pi.exerciseId = obj[QLatin1String("exerciseId")].toInt();
|
||||
pi.forceId = obj[QLatin1String("forceId")].toInt();
|
||||
pi.typeId = obj[QLatin1String("typeId")].toInt();
|
||||
pi.isDeleted = obj[QLatin1String("isDeleted")].toBool();
|
||||
pi.equipTypeId = obj[QLatin1String("equipTypeId")].toInt();
|
||||
pi.typeClassId = obj[QLatin1String("typeClassId")].toInt();
|
||||
pi.symbolColor = obj[QLatin1String("symbolColor")].toInt();
|
||||
pi.symbolPNG = QByteArray::fromBase64(obj[QLatin1String("symbolPNG")].toString().toLatin1());
|
||||
pi.hierarchy = obj[QLatin1String("hierarchy")].toString();
|
||||
pi.designator = obj[QLatin1String("designator")].toString();
|
||||
pi.tactIdent = obj[QLatin1String("tactIdent")].toString();
|
||||
pi.info = obj[QLatin1String("info")].toString();
|
||||
pi.alias = obj[QLatin1String("alias")].toString();
|
||||
pi.forceName = obj[QLatin1String("forceName")].toString();
|
||||
|
||||
return pi;
|
||||
}
|
||||
@@ -66,8 +66,8 @@ QJsonObject PlayerInfo::toJsonAll() const
|
||||
arr.append(toJson(pi));
|
||||
|
||||
QJsonObject retMap;
|
||||
retMap[QLatin1String("piMap")] = arr;
|
||||
retMap[QLatin1String("ok")] = m_ok;
|
||||
retMap[QLatin1String("piMap")] = arr;
|
||||
retMap[QLatin1String("ok")] = m_ok;
|
||||
|
||||
return retMap;
|
||||
}
|
||||
@@ -92,25 +92,25 @@ PlayerInfo PlayerInfo::fromJsonAll(const QJsonObject &map)
|
||||
QVariantMap PlayerInfo::toVariantMap() const
|
||||
{
|
||||
QVariantMap retMap;
|
||||
retMap[QLatin1String("playerId")] = QVariant(m_playerInfo.playerId);
|
||||
retMap[QLatin1String("parentPlayerId")] = QVariant(m_playerInfo.parentPlayerId);
|
||||
retMap[QLatin1String("equipNo")] = QVariant(m_playerInfo.equipNo);
|
||||
retMap[QLatin1String("equipTypeId")] = QVariant(m_playerInfo.equipTypeId);
|
||||
retMap[QLatin1String("typeClassId")] = QVariant(m_playerInfo.typeClassId);
|
||||
retMap[QLatin1String("forceId")] = QVariant(m_playerInfo.forceId);
|
||||
retMap[QLatin1String("designator")] = m_playerInfo.designator;
|
||||
retMap[QLatin1String("tactIdent")] = m_playerInfo.tactIdent;
|
||||
retMap[QLatin1String("hierarchy")] = m_playerInfo.hierarchy;
|
||||
retMap[QLatin1String("forceName")] = m_playerInfo.forceName;
|
||||
retMap[QLatin1String("info")] = m_playerInfo.info;
|
||||
retMap[QLatin1String("alias")] = m_playerInfo.alias;
|
||||
retMap[QLatin1String("symbolPNG")] = QVariant(m_playerInfo.symbolPNG);
|
||||
retMap[QLatin1String("symbolColor")] = QVariant(m_playerInfo.symbolColor);
|
||||
retMap[QLatin1String("playerId")] = QVariant(m_playerInfo.playerId);
|
||||
retMap[QLatin1String("parentPlayerId")] = QVariant(m_playerInfo.parentPlayerId);
|
||||
retMap[QLatin1String("equipNo")] = QVariant(m_playerInfo.equipNo);
|
||||
retMap[QLatin1String("equipTypeId")] = QVariant(m_playerInfo.equipTypeId);
|
||||
retMap[QLatin1String("typeClassId")] = QVariant(m_playerInfo.typeClassId);
|
||||
retMap[QLatin1String("forceId")] = QVariant(m_playerInfo.forceId);
|
||||
retMap[QLatin1String("designator")] = m_playerInfo.designator;
|
||||
retMap[QLatin1String("tactIdent")] = m_playerInfo.tactIdent;
|
||||
retMap[QLatin1String("hierarchy")] = m_playerInfo.hierarchy;
|
||||
retMap[QLatin1String("forceName")] = m_playerInfo.forceName;
|
||||
retMap[QLatin1String("info")] = m_playerInfo.info;
|
||||
retMap[QLatin1String("alias")] = m_playerInfo.alias;
|
||||
retMap[QLatin1String("symbolPNG")] = QVariant(m_playerInfo.symbolPNG);
|
||||
retMap[QLatin1String("symbolColor")] = QVariant(m_playerInfo.symbolColor);
|
||||
|
||||
retMap[QLatin1String("assignState")] = QVariant(m_playerInfo.assignState);
|
||||
retMap[QLatin1String("playerState")] = QVariant(m_playerInfo.playerState);
|
||||
retMap[QLatin1String("assignState")] = QVariant(m_playerInfo.assignState);
|
||||
retMap[QLatin1String("playerState")] = QVariant(m_playerInfo.playerState);
|
||||
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return retMap;
|
||||
}
|
||||
@@ -119,24 +119,24 @@ PlayerInfo PlayerInfo::fromVariantMap(const QVariantMap &map)
|
||||
{
|
||||
PlayerInfo pi;
|
||||
|
||||
pi.m_playerInfo.playerId = map[QLatin1String("playerId")].toInt();
|
||||
pi.m_playerInfo.playerId = map[QLatin1String("playerId")].toInt();
|
||||
pi.m_playerInfo.parentPlayerId = map[QLatin1String("parentPlayerId")].toInt();
|
||||
pi.m_playerInfo.equipNo = map[QLatin1String("equipNo")].toInt();
|
||||
pi.m_playerInfo.forceId = map[QLatin1String("forceId")].toInt();
|
||||
pi.m_playerInfo.equipTypeId = map[QLatin1String("equipTypeId")].toInt();
|
||||
pi.m_playerInfo.typeClassId = map[QLatin1String("typeClassId")].toInt();
|
||||
pi.m_playerInfo.designator = map[QLatin1String("designator")].toString();
|
||||
pi.m_playerInfo.tactIdent = map[QLatin1String("tactIdent")].toString();
|
||||
pi.m_playerInfo.hierarchy = map[QLatin1String("hierarchy")].toString();
|
||||
pi.m_playerInfo.forceName = map[QLatin1String("forceName")].toString();
|
||||
pi.m_playerInfo.info = map[QLatin1String("info")].toString();
|
||||
pi.m_playerInfo.alias = map[QLatin1String("alias")].toString();
|
||||
pi.m_playerInfo.symbolPNG = map[QLatin1String("symbolPNG")].toByteArray();
|
||||
pi.m_playerInfo.symbolColor = map[QLatin1String("symbolColor")].toInt();
|
||||
pi.m_playerInfo.assignState = (IWMS2ECC::PlayerAssignState) map[QLatin1String("assignState")].toInt();
|
||||
pi.m_playerInfo.playerState = (IWMS2ECC::PlayerState) map[QLatin1String("playerState")].toInt();
|
||||
pi.m_playerInfo.equipNo = map[QLatin1String("equipNo")].toInt();
|
||||
pi.m_playerInfo.forceId = map[QLatin1String("forceId")].toInt();
|
||||
pi.m_playerInfo.equipTypeId = map[QLatin1String("equipTypeId")].toInt();
|
||||
pi.m_playerInfo.typeClassId = map[QLatin1String("typeClassId")].toInt();
|
||||
pi.m_playerInfo.designator = map[QLatin1String("designator")].toString();
|
||||
pi.m_playerInfo.tactIdent = map[QLatin1String("tactIdent")].toString();
|
||||
pi.m_playerInfo.hierarchy = map[QLatin1String("hierarchy")].toString();
|
||||
pi.m_playerInfo.forceName = map[QLatin1String("forceName")].toString();
|
||||
pi.m_playerInfo.info = map[QLatin1String("info")].toString();
|
||||
pi.m_playerInfo.alias = map[QLatin1String("alias")].toString();
|
||||
pi.m_playerInfo.symbolPNG = map[QLatin1String("symbolPNG")].toByteArray();
|
||||
pi.m_playerInfo.symbolColor = map[QLatin1String("symbolColor")].toInt();
|
||||
pi.m_playerInfo.assignState = (IWMS2ECC::PlayerAssignState)map[QLatin1String("assignState")].toInt();
|
||||
pi.m_playerInfo.playerState = (IWMS2ECC::PlayerState)map[QLatin1String("playerState")].toInt();
|
||||
|
||||
pi.m_ok = map[QLatin1String("ok")].toBool();
|
||||
pi.m_ok = map[QLatin1String("ok")].toBool();
|
||||
|
||||
return pi;
|
||||
}
|
||||
@@ -146,13 +146,13 @@ QVariantMap PlayerInfo::toVariantMapAll() const
|
||||
QVariantMap vMap;
|
||||
for (const IWMS2ECC::PlayerInfo &pi : m_allPlayerInfo)
|
||||
{
|
||||
m_playerInfo = pi;
|
||||
m_playerInfo = pi;
|
||||
vMap.insert(QString::number(pi.playerId), QVariant(toVariantMap()));
|
||||
}
|
||||
|
||||
QVariantMap retMap;
|
||||
retMap[QLatin1String("plMap")] = QVariant(vMap);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
retMap[QLatin1String("plMap")] = QVariant(vMap);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return retMap;
|
||||
}
|
||||
@@ -172,5 +172,3 @@ PlayerInfo PlayerInfo::fromVariantMapAll(const QVariantMap &map)
|
||||
players.m_ok = vMap[QLatin1String("ok")].toBool();
|
||||
return players;
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+2
-3
@@ -34,7 +34,6 @@ public:
|
||||
|
||||
private:
|
||||
QMap<int, IWMS2ECC::PlayerInfo> m_allPlayerInfo;
|
||||
mutable IWMS2ECC::PlayerInfo m_playerInfo;
|
||||
bool m_ok = false;
|
||||
mutable IWMS2ECC::PlayerInfo m_playerInfo;
|
||||
bool m_ok = false;
|
||||
};
|
||||
|
||||
Executable → Regular
+26
-26
@@ -8,17 +8,17 @@ QJsonObject Registration::toJson() const
|
||||
{
|
||||
QJsonObject obj;
|
||||
|
||||
obj[QLatin1String("playerId")] = m_playerId;
|
||||
obj[QLatin1String("playerId")] = m_playerId;
|
||||
obj[QLatin1String("assignment")] = m_assignment;
|
||||
obj[QLatin1String("exerciseId")] = m_exerciseId;
|
||||
obj[QLatin1String("ok")] = m_ok;
|
||||
obj[QLatin1String("ok")] = m_ok;
|
||||
|
||||
if (m_bEquipNoIsSet)
|
||||
obj[QLatin1String("equipNo")] = m_equipNo;
|
||||
obj[QLatin1String("equipNo")] = m_equipNo;
|
||||
if (m_bAliasIsSet)
|
||||
obj[QLatin1String("alias")] = m_alias;
|
||||
obj[QLatin1String("alias")] = m_alias;
|
||||
if (m_bInfoIsSet)
|
||||
obj[QLatin1String("info")] = m_info;
|
||||
obj[QLatin1String("info")] = m_info;
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -27,20 +27,20 @@ Registration Registration::fromJson(const QJsonObject &obj)
|
||||
{
|
||||
Registration rg;
|
||||
|
||||
rg.m_playerId = obj[QLatin1String("playerId")].toInt();
|
||||
rg.m_assignment = IWMS2ECC::int2PlayerAssignState(obj[QLatin1String("assignment")].toInt());
|
||||
rg.m_exerciseId = obj[QLatin1String("exerciseId")].toInt();
|
||||
rg.m_playerId = obj[QLatin1String("playerId")].toInt();
|
||||
rg.m_assignment = IWMS2ECC::int2PlayerAssignState(obj[QLatin1String("assignment")].toInt());
|
||||
rg.m_exerciseId = obj[QLatin1String("exerciseId")].toInt();
|
||||
|
||||
rg.m_bEquipNoIsSet = obj.contains(QLatin1String("equipNo"));
|
||||
if (rg.m_bEquipNoIsSet)
|
||||
rg.m_equipNo = obj[QLatin1String("equipNo")].toInt();
|
||||
rg.m_bAliasIsSet = obj.contains(QLatin1String("alias"));
|
||||
rg.m_bAliasIsSet = obj.contains(QLatin1String("alias"));
|
||||
if (rg.m_bAliasIsSet)
|
||||
rg.m_alias = obj[QLatin1String("alias")].toString();
|
||||
rg.m_bInfoIsSet = obj.contains(QLatin1String("info"));
|
||||
rg.m_bInfoIsSet = obj.contains(QLatin1String("info"));
|
||||
if (rg.m_bInfoIsSet)
|
||||
rg.m_info = obj[QLatin1String("info")].toString();
|
||||
rg.m_ok = obj[QLatin1String("ok")].toBool();
|
||||
rg.m_info = obj[QLatin1String("info")].toString();
|
||||
rg.m_ok = obj[QLatin1String("ok")].toBool();
|
||||
|
||||
return rg;
|
||||
}
|
||||
@@ -50,18 +50,18 @@ QVariantMap Registration::toVariantMap() const
|
||||
{
|
||||
QVariantMap retMap;
|
||||
|
||||
retMap[QLatin1String("playerId")] = QVariant(m_playerId);
|
||||
retMap[QLatin1String("playerId")] = QVariant(m_playerId);
|
||||
retMap[QLatin1String("assignment")] = QVariant(m_assignment);
|
||||
retMap[QLatin1String("exerciseId")] = QVariant(m_exerciseId);
|
||||
|
||||
if (m_bEquipNoIsSet)
|
||||
retMap[QLatin1String("equipNo")] = QVariant(m_equipNo);
|
||||
retMap[QLatin1String("equipNo")] = QVariant(m_equipNo);
|
||||
if (m_bAliasIsSet)
|
||||
retMap[QLatin1String("alias")] = m_alias;
|
||||
retMap[QLatin1String("alias")] = m_alias;
|
||||
if (m_bInfoIsSet)
|
||||
retMap[QLatin1String("info")] = m_info;
|
||||
retMap[QLatin1String("info")] = m_info;
|
||||
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return retMap;
|
||||
}
|
||||
@@ -70,20 +70,20 @@ Registration Registration::fromVariantMap(const QVariantMap &map)
|
||||
{
|
||||
Registration rg;
|
||||
|
||||
rg.m_playerId = map[QLatin1String("playerId")].toInt();
|
||||
rg.m_assignment = IWMS2ECC::int2PlayerAssignState(map[QLatin1String("assignment")].toInt());
|
||||
rg.m_exerciseId = map[QLatin1String("exerciseId")].toInt();
|
||||
rg.m_ok = map[QLatin1String("ok")].toBool();
|
||||
rg.m_playerId = map[QLatin1String("playerId")].toInt();
|
||||
rg.m_assignment = IWMS2ECC::int2PlayerAssignState(map[QLatin1String("assignment")].toInt());
|
||||
rg.m_exerciseId = map[QLatin1String("exerciseId")].toInt();
|
||||
rg.m_ok = map[QLatin1String("ok")].toBool();
|
||||
|
||||
rg.m_bEquipNoIsSet = map.contains(QLatin1String("equipNo"));
|
||||
if (rg.m_bEquipNoIsSet)
|
||||
rg.m_equipNo = map[QLatin1String("equipNo")].toInt();
|
||||
rg.m_bAliasIsSet = map.contains(QLatin1String("alias"));
|
||||
rg.m_equipNo = map[QLatin1String("equipNo")].toInt();
|
||||
rg.m_bAliasIsSet = map.contains(QLatin1String("alias"));
|
||||
if (rg.m_bAliasIsSet)
|
||||
rg.m_alias = map[QLatin1String("alias")].toString();
|
||||
rg.m_bInfoIsSet = map.contains(QLatin1String("info"));
|
||||
rg.m_alias = map[QLatin1String("alias")].toString();
|
||||
rg.m_bInfoIsSet = map.contains(QLatin1String("info"));
|
||||
if (rg.m_bInfoIsSet)
|
||||
rg.m_info = map[QLatin1String("info")].toString();
|
||||
rg.m_info = map[QLatin1String("info")].toString();
|
||||
|
||||
return rg;
|
||||
}
|
||||
Executable → Regular
+30
-19
@@ -19,37 +19,48 @@ public:
|
||||
QVariantMap toVariantMap() const;
|
||||
static Registration fromVariantMap(const QVariantMap &map);
|
||||
|
||||
int getPlayerId() const { return m_playerId; }
|
||||
int getEquipNo() const { return m_equipNo; }
|
||||
int getPlayerId() const { return m_playerId; }
|
||||
int getEquipNo() const { return m_equipNo; }
|
||||
int getExerciseId() const { return m_exerciseId; }
|
||||
QString getAlias() const { return m_alias; }
|
||||
QString getInfo() const { return m_info; }
|
||||
QString getAlias() const { return m_alias; }
|
||||
QString getInfo() const { return m_info; }
|
||||
bool isEquipNoSet() const { return m_bEquipNoIsSet; }
|
||||
bool isAliasSet() const { return m_bAliasIsSet; }
|
||||
bool isInfoSet() const { return m_bInfoIsSet; }
|
||||
bool isAliasSet() const { return m_bAliasIsSet; }
|
||||
bool isInfoSet() const { return m_bInfoIsSet; }
|
||||
|
||||
IWMS2ECC::PlayerAssignState getAssignment() const { return m_assignment; }
|
||||
|
||||
bool getOk() const { return m_ok; }
|
||||
|
||||
void setPlayerId(int playerId) { m_playerId = playerId; }
|
||||
void setEquipNo(int equipNo) { m_equipNo = equipNo; m_bEquipNoIsSet = true; }
|
||||
void setEquipNo(int equipNo)
|
||||
{
|
||||
m_equipNo = equipNo;
|
||||
m_bEquipNoIsSet = true;
|
||||
}
|
||||
void setAssignment(IWMS2ECC::PlayerAssignState assignment) { m_assignment = assignment; }
|
||||
void setExerciseId(int exerciseId) { m_exerciseId = exerciseId; }
|
||||
void setAlias(const QString &alias) { m_alias = alias; m_bAliasIsSet = true; }
|
||||
void setInfo(const QString &info) { m_info = info; m_bInfoIsSet = true; }
|
||||
void setAlias(const QString &alias)
|
||||
{
|
||||
m_alias = alias;
|
||||
m_bAliasIsSet = true;
|
||||
}
|
||||
void setInfo(const QString &info)
|
||||
{
|
||||
m_info = info;
|
||||
m_bInfoIsSet = true;
|
||||
}
|
||||
void setOk(bool ok) { m_ok = ok; }
|
||||
|
||||
private:
|
||||
QString m_alias;
|
||||
QString m_info;
|
||||
QString m_alias;
|
||||
QString m_info;
|
||||
IWMS2ECC::PlayerAssignState m_assignment = IWMS2ECC::UNDEFINED;
|
||||
int m_playerId = 0;
|
||||
int m_equipNo = 0;
|
||||
int m_exerciseId = -1;
|
||||
bool m_bEquipNoIsSet = false;
|
||||
bool m_bAliasIsSet = false;
|
||||
bool m_bInfoIsSet = false;
|
||||
bool m_ok = false;
|
||||
int m_playerId = 0;
|
||||
int m_equipNo = 0;
|
||||
int m_exerciseId = -1;
|
||||
bool m_bEquipNoIsSet = false;
|
||||
bool m_bAliasIsSet = false;
|
||||
bool m_bInfoIsSet = false;
|
||||
bool m_ok = false;
|
||||
};
|
||||
|
||||
Executable → Regular
+12
-13
@@ -8,9 +8,9 @@ QJsonObject Unregister::toJson() const
|
||||
{
|
||||
QJsonObject obj;
|
||||
|
||||
obj[QLatin1String("equipNo")] = m_equipNo;
|
||||
obj[QLatin1String("exerciseId")] = m_exerciseId;
|
||||
obj[QLatin1String("ok")] = m_ok;
|
||||
obj[QLatin1String("equipNo")] = m_equipNo;
|
||||
obj[QLatin1String("exerciseId")] = m_exerciseId;
|
||||
obj[QLatin1String("ok")] = m_ok;
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -19,9 +19,9 @@ Unregister Unregister::fromJson(const QJsonObject &obj)
|
||||
{
|
||||
Unregister ur;
|
||||
|
||||
ur.m_equipNo = obj[QLatin1String("equipNo")].toInt();
|
||||
ur.m_exerciseId = obj[QLatin1String("exerciseId")].toInt();
|
||||
ur.m_ok = obj[QLatin1String("ok")].toBool();
|
||||
ur.m_equipNo = obj[QLatin1String("equipNo")].toInt();
|
||||
ur.m_exerciseId = obj[QLatin1String("exerciseId")].toInt();
|
||||
ur.m_ok = obj[QLatin1String("ok")].toBool();
|
||||
|
||||
return ur;
|
||||
}
|
||||
@@ -30,9 +30,9 @@ QVariantMap Unregister::toVariantMap() const
|
||||
{
|
||||
QVariantMap retMap;
|
||||
|
||||
retMap[QLatin1String("equipNo")] = QVariant(m_equipNo);
|
||||
retMap[QLatin1String("exerciseId")] = QVariant(m_exerciseId);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
retMap[QLatin1String("equipNo")] = QVariant(m_equipNo);
|
||||
retMap[QLatin1String("exerciseId")] = QVariant(m_exerciseId);
|
||||
retMap[QLatin1String("ok")] = QVariant(m_ok);
|
||||
|
||||
return retMap;
|
||||
}
|
||||
@@ -41,10 +41,9 @@ Unregister Unregister::fromVariantMap(const QVariantMap &map)
|
||||
{
|
||||
Unregister ur;
|
||||
|
||||
ur.m_equipNo = map[QLatin1String("equipNo")].toInt();
|
||||
ur.m_exerciseId = map[QLatin1String("exerciseId")].toInt();
|
||||
ur.m_ok = map[QLatin1String("ok")].toBool();
|
||||
ur.m_equipNo = map[QLatin1String("equipNo")].toInt();
|
||||
ur.m_exerciseId = map[QLatin1String("exerciseId")].toInt();
|
||||
ur.m_ok = map[QLatin1String("ok")].toBool();
|
||||
|
||||
return ur;
|
||||
}
|
||||
|
||||
Executable → Regular
+3
-3
@@ -26,7 +26,7 @@ public:
|
||||
void setOk(bool ok) { m_ok = ok; }
|
||||
|
||||
private:
|
||||
int m_equipNo = 0;
|
||||
int m_exerciseId = -1;
|
||||
bool m_ok = false;
|
||||
int m_equipNo = 0;
|
||||
int m_exerciseId = -1;
|
||||
bool m_ok = false;
|
||||
};
|
||||
Executable → Regular
+2
-2
@@ -3,8 +3,8 @@
|
||||
#include "ngl_signal_handler.inc"
|
||||
|
||||
NGLApplication::NGLApplication(int &argc, char **argv)
|
||||
: QApplication(argc, argv)
|
||||
{
|
||||
: QApplication(argc, argv)
|
||||
{
|
||||
signal(SIGTERM, &signalHandler);
|
||||
#ifdef Q_OS_WIN
|
||||
installNativeEventFilter(new MyEventFilter);
|
||||
|
||||
Executable → Regular
+14
-12
@@ -6,23 +6,25 @@
|
||||
#include "nglloggerhandler.h"
|
||||
|
||||
#ifndef NGLAPPLICATION_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLAPPLICATION_EXPORT
|
||||
# else
|
||||
# ifdef MAKE_NGLAPPLICATION_LIB
|
||||
# define NGLAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define NGLAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLAPPLICATION_EXPORT
|
||||
#else
|
||||
#ifdef MAKE_NGLAPPLICATION_LIB
|
||||
#define NGLAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define NGLAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class NGLAPPLICATION_EXPORT NGLApplication : public QApplication, public NGL::LoggerHandler
|
||||
class NGLAPPLICATION_EXPORT NGLApplication
|
||||
: public QApplication
|
||||
, public NGL::LoggerHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -33,4 +35,4 @@ protected:
|
||||
bool notify(QObject *o, QEvent *e) override;
|
||||
};
|
||||
|
||||
#define nglApp static_cast<NGLApplication*>(NGLApplication::instance())
|
||||
#define nglApp static_cast<NGLApplication *>(NGLApplication::instance())
|
||||
Executable → Regular
+2
-2
@@ -2,8 +2,8 @@
|
||||
#include "ngl_signal_handler.inc"
|
||||
|
||||
NGLCoreApplication::NGLCoreApplication(int &argc, char **argv)
|
||||
: QCoreApplication(argc, argv)
|
||||
{
|
||||
: QCoreApplication(argc, argv)
|
||||
{
|
||||
signal(SIGTERM, &signalHandler);
|
||||
#ifdef Q_OS_WIN
|
||||
installNativeEventFilter(new MyEventFilter);
|
||||
|
||||
Executable → Regular
+13
-11
@@ -4,23 +4,25 @@
|
||||
#include "nglloggerhandler.h"
|
||||
|
||||
#ifndef NGLCOREAPPLICATION_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLCOREAPPLICATION_EXPORT
|
||||
# else
|
||||
# ifdef MAKE_NGLCOREAPPLICATION_LIB
|
||||
# define NGLCOREAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define NGLCOREAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLCOREAPPLICATION_EXPORT
|
||||
#else
|
||||
#ifdef MAKE_NGLCOREAPPLICATION_LIB
|
||||
#define NGLCOREAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define NGLCOREAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class NGLCOREAPPLICATION_EXPORT NGLCoreApplication : public QCoreApplication, public NGL::LoggerHandler
|
||||
class NGLCOREAPPLICATION_EXPORT NGLCoreApplication
|
||||
: public QCoreApplication
|
||||
, public NGL::LoggerHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
Executable → Regular
+2
-2
@@ -2,8 +2,8 @@
|
||||
#include "ngl_signal_handler.inc"
|
||||
|
||||
NGLGuiApplication::NGLGuiApplication(int &argc, char **argv)
|
||||
: QGuiApplication(argc, argv)
|
||||
{
|
||||
: QGuiApplication(argc, argv)
|
||||
{
|
||||
signal(SIGTERM, &signalHandler);
|
||||
#ifdef Q_OS_WIN
|
||||
installNativeEventFilter(new MyEventFilter);
|
||||
|
||||
Executable → Regular
+14
-12
@@ -4,23 +4,25 @@
|
||||
#include "nglloggerhandler.h"
|
||||
|
||||
#ifndef NGLGUIAPPLICATION_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLGUIAPPLICATION_EXPORT
|
||||
# else
|
||||
# ifdef MAKE_NGLGUIAPPLICATION_LIB
|
||||
# define NGLGUIAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define NGLGUIAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLGUIAPPLICATION_EXPORT
|
||||
#else
|
||||
#ifdef MAKE_NGLGUIAPPLICATION_LIB
|
||||
#define NGLGUIAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define NGLGUIAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class NGLGUIAPPLICATION_EXPORT NGLGuiApplication : public QGuiApplication, public NGL::LoggerHandler
|
||||
class NGLGUIAPPLICATION_EXPORT NGLGuiApplication
|
||||
: public QGuiApplication
|
||||
, public NGL::LoggerHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -28,4 +30,4 @@ public:
|
||||
NGLGuiApplication(int &argc, char **argv);
|
||||
};
|
||||
|
||||
#define nglGuiApp static_cast<NGLGuiApplication*>(NGLGuiApplication::instance())
|
||||
#define nglGuiApp static_cast<NGLGuiApplication *>(NGLGuiApplication::instance())
|
||||
Executable → Regular
+65
-65
@@ -7,72 +7,72 @@
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
static QByteArray username()
|
||||
{
|
||||
static QByteArray username()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
return qgetenv("USERNAME");
|
||||
return qgetenv("USERNAME");
|
||||
#else
|
||||
return qgetenv("USER");
|
||||
return qgetenv("USER");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void setEnvVars()
|
||||
{
|
||||
const QString logPath = NGL::Settings::logPath();
|
||||
qputenv("LOG4QT_LOGDIR", logPath.toLocal8Bit());
|
||||
qputenv("LOG4QT_USER", username());
|
||||
}
|
||||
|
||||
void LoggerHandler::createLogger(const QByteArray &baseName, const char *configFileName, bool quiet)
|
||||
{
|
||||
setEnvVars();
|
||||
m_baseLoggerName = baseName;
|
||||
|
||||
const QString bnStr(QString::fromLatin1(baseName.toLower()));
|
||||
const QString logPath = NGL::Settings::logPath();
|
||||
m_loggerFilenamePostfix = logPath + QLatin1Char('/') + QString::fromLocal8Bit(username()) + QLatin1Char('_') + bnStr;
|
||||
m_loggerFilenamePrefix = QLatin1String(".log");
|
||||
|
||||
const QString logOutputName = m_loggerFilenamePostfix + m_loggerFilenamePrefix;
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger(QString::fromLatin1(configFileName), false, logOutputName, quiet);
|
||||
|
||||
qInstallMessageHandler(&qtMsgHandler);
|
||||
}
|
||||
|
||||
void LoggerHandler::createLogger(const QByteArray &baseName, int exerciseId, int additionalId, bool quiet)
|
||||
{
|
||||
setEnvVars();
|
||||
|
||||
const QString bnStr(QString::fromLatin1(baseName.toLower()));
|
||||
const QString configFileName = QLatin1String("log4cxx_") + bnStr + QLatin1String(".props");
|
||||
const QString logPath = NGL::Settings::logPath();
|
||||
m_loggerFilenamePostfix = logPath + QLatin1Char('/') + QString::fromLocal8Bit(username()) + QLatin1Char('_') + bnStr;
|
||||
if (exerciseId > 0)
|
||||
m_loggerFilenamePostfix += QLatin1Char('_') + QString::number(exerciseId);
|
||||
if (additionalId > 0)
|
||||
m_loggerFilenamePostfix += QLatin1Char('_') + QString::number(additionalId);
|
||||
|
||||
m_loggerFilenamePrefix = QLatin1String(".log");
|
||||
m_baseLoggerName = baseName + QByteArray(".main");
|
||||
|
||||
const QString logOutputName = m_loggerFilenamePostfix + m_loggerFilenamePrefix;
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger(configFileName, false, logOutputName, quiet);
|
||||
qInstallMessageHandler(&qtMsgHandler);
|
||||
}
|
||||
|
||||
NGL::INGLLogger &LoggerHandler::baseLogger() const
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(m_baseLoggerName.data());
|
||||
}
|
||||
|
||||
NGL::INGLLogger &LoggerHandler::logger(const char *loggerName) const
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(loggerName);
|
||||
}
|
||||
|
||||
LoggerHandler *LoggerHandler::getLoggerHandler()
|
||||
{
|
||||
return dynamic_cast<LoggerHandler *>(QCoreApplication::instance());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void setEnvVars()
|
||||
{
|
||||
const QString logPath = NGL::Settings::logPath();
|
||||
qputenv("LOG4QT_LOGDIR", logPath.toLocal8Bit());
|
||||
qputenv("LOG4QT_USER", username());
|
||||
}
|
||||
|
||||
void LoggerHandler::createLogger(const QByteArray &baseName, const char *configFileName, bool quiet)
|
||||
{
|
||||
setEnvVars();
|
||||
m_baseLoggerName = baseName;
|
||||
|
||||
const QString bnStr(QString::fromLatin1(baseName.toLower()));
|
||||
const QString logPath = NGL::Settings::logPath();
|
||||
m_loggerFilenamePostfix = logPath + QLatin1Char('/') + QString::fromLocal8Bit(username()) + QLatin1Char('_') + bnStr;
|
||||
m_loggerFilenamePrefix = QLatin1String(".log");
|
||||
|
||||
const QString logOutputName = m_loggerFilenamePostfix + m_loggerFilenamePrefix;
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger(QString::fromLatin1(configFileName), false, logOutputName, quiet);
|
||||
|
||||
qInstallMessageHandler(&qtMsgHandler);
|
||||
}
|
||||
|
||||
void LoggerHandler::createLogger(const QByteArray &baseName, int exerciseId, int additionalId, bool quiet)
|
||||
{
|
||||
setEnvVars();
|
||||
|
||||
const QString bnStr(QString::fromLatin1(baseName.toLower()));
|
||||
const QString configFileName = QLatin1String("log4cxx_") + bnStr + QLatin1String(".props");
|
||||
const QString logPath = NGL::Settings::logPath();
|
||||
m_loggerFilenamePostfix = logPath + QLatin1Char('/') + QString::fromLocal8Bit(username()) + QLatin1Char('_') + bnStr;
|
||||
if (exerciseId > 0)
|
||||
m_loggerFilenamePostfix += QLatin1Char('_') + QString::number(exerciseId);
|
||||
if (additionalId > 0)
|
||||
m_loggerFilenamePostfix += QLatin1Char('_') + QString::number(additionalId);
|
||||
|
||||
m_loggerFilenamePrefix = QLatin1String(".log");
|
||||
m_baseLoggerName = baseName + QByteArray(".main");
|
||||
|
||||
const QString logOutputName = m_loggerFilenamePostfix + m_loggerFilenamePrefix;
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger(configFileName, false, logOutputName, quiet);
|
||||
qInstallMessageHandler(&qtMsgHandler);
|
||||
}
|
||||
|
||||
NGL::INGLLogger &LoggerHandler::baseLogger() const
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(m_baseLoggerName.data());
|
||||
}
|
||||
|
||||
NGL::INGLLogger &LoggerHandler::logger(const char *loggerName) const
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(loggerName);
|
||||
}
|
||||
|
||||
LoggerHandler *LoggerHandler::getLoggerHandler()
|
||||
{
|
||||
return dynamic_cast<LoggerHandler*>(QCoreApplication::instance());
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+30
-40
@@ -6,62 +6,52 @@
|
||||
#include <QtCore/QString>
|
||||
|
||||
#ifndef LOGGERHANDLER_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define LOGGERHANDLER_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_NGLCOREAPPLICATION_LIB) || defined(MAKE_NGLGUIAPPLICATION_LIB) || defined(MAKE_NGLAPPLICATION_LIB) || defined(MAKE_NGLSINGLECOREAPPLICATION_LIB) || defined(MAKE_NGLSINGLEAPPLICATION_LIB)
|
||||
# define LOGGERHANDLER_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define LOGGERHANDLER_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define LOGGERHANDLER_EXPORT
|
||||
#else
|
||||
#if defined(MAKE_NGLCOREAPPLICATION_LIB) || defined(MAKE_NGLGUIAPPLICATION_LIB) || defined(MAKE_NGLAPPLICATION_LIB) || defined(MAKE_NGLSINGLECOREAPPLICATION_LIB) || \
|
||||
defined(MAKE_NGLSINGLEAPPLICATION_LIB)
|
||||
#define LOGGERHANDLER_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define LOGGERHANDLER_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
|
||||
class LOGGERHANDLER_EXPORT LoggerHandler
|
||||
{
|
||||
public:
|
||||
LoggerHandler() = default;
|
||||
~LoggerHandler() = default;
|
||||
class LOGGERHANDLER_EXPORT LoggerHandler
|
||||
{
|
||||
public:
|
||||
LoggerHandler() = default;
|
||||
~LoggerHandler() = default;
|
||||
|
||||
|
||||
|
||||
void createLogger(const QByteArray &baseName,
|
||||
const char *configFileName,
|
||||
bool quiet = false);
|
||||
void createLogger(const QByteArray &baseName, const char *configFileName, bool quiet = false);
|
||||
|
||||
|
||||
|
||||
void createLogger(const QByteArray &baseName,
|
||||
int exerciseId = 0,
|
||||
int additionalId = 0,
|
||||
bool quiet = false);
|
||||
void createLogger(const QByteArray &baseName, int exerciseId = 0, int additionalId = 0, bool quiet = false);
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger &baseLogger() const;
|
||||
NGL::INGLLogger &baseLogger() const;
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger &logger(const char *loggerName) const;
|
||||
NGL::INGLLogger &logger(const char *loggerName) const;
|
||||
|
||||
|
||||
|
||||
QString loggerNamePostfix() const { return m_loggerFilenamePostfix; }
|
||||
QString loggerNamePostfix() const { return m_loggerFilenamePostfix; }
|
||||
|
||||
|
||||
|
||||
QString loggerNamePrefix() const { return m_loggerFilenamePrefix; }
|
||||
QString loggerNamePrefix() const { return m_loggerFilenamePrefix; }
|
||||
|
||||
|
||||
|
||||
static LoggerHandler *getLoggerHandler();
|
||||
private:
|
||||
QByteArray m_baseLoggerName;
|
||||
QString m_loggerFilenamePostfix;
|
||||
QString m_loggerFilenamePrefix;
|
||||
};
|
||||
}
|
||||
static LoggerHandler *getLoggerHandler();
|
||||
|
||||
private:
|
||||
QByteArray m_baseLoggerName;
|
||||
QString m_loggerFilenamePostfix;
|
||||
QString m_loggerFilenamePrefix;
|
||||
};
|
||||
}
|
||||
Executable → Regular
+2
-2
@@ -7,9 +7,9 @@
|
||||
|
||||
|
||||
NGLSingleApplication::NGLSingleApplication(int &argc, char **argv)
|
||||
: QtSingleApplication(argc, argv)
|
||||
: QtSingleApplication(argc, argv)
|
||||
{
|
||||
|
||||
|
||||
signal(SIGTERM, &signalHandler);
|
||||
#ifdef Q_OS_WIN
|
||||
installNativeEventFilter(new MyEventFilter);
|
||||
|
||||
Executable → Regular
+14
-12
@@ -5,23 +5,25 @@
|
||||
#include "nglloggerhandler.h"
|
||||
|
||||
#ifndef NGLSINGLEAPPLICATION_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLSINGLEAPPLICATION_EXPORT
|
||||
# else
|
||||
# ifdef MAKE_NGLSINGLEAPPLICATION_LIB
|
||||
# define NGLSINGLEAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define NGLSINGLEAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLSINGLEAPPLICATION_EXPORT
|
||||
#else
|
||||
#ifdef MAKE_NGLSINGLEAPPLICATION_LIB
|
||||
#define NGLSINGLEAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define NGLSINGLEAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class NGLSINGLEAPPLICATION_EXPORT NGLSingleApplication : public QtSingleApplication, public NGL::LoggerHandler
|
||||
class NGLSINGLEAPPLICATION_EXPORT NGLSingleApplication
|
||||
: public QtSingleApplication
|
||||
, public NGL::LoggerHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -32,4 +34,4 @@ protected:
|
||||
bool notify(QObject *o, QEvent *e) override;
|
||||
};
|
||||
|
||||
#define nglApp static_cast<NGLSingleApplication*>(NGLSingleApplication::instance())
|
||||
#define nglApp static_cast<NGLSingleApplication *>(NGLSingleApplication::instance())
|
||||
Executable → Regular
+2
-2
@@ -2,8 +2,8 @@
|
||||
#include "ngl_signal_handler.inc"
|
||||
|
||||
NGLSingleCoreApplication::NGLSingleCoreApplication(int &argc, char **argv)
|
||||
: QtSingleCoreApplication(argc, argv)
|
||||
{
|
||||
: QtSingleCoreApplication(argc, argv)
|
||||
{
|
||||
signal(SIGTERM, &signalHandler);
|
||||
#ifdef Q_OS_WIN
|
||||
installNativeEventFilter(new MyEventFilter);
|
||||
|
||||
Executable → Regular
+13
-11
@@ -4,23 +4,25 @@
|
||||
#include "nglloggerhandler.h"
|
||||
|
||||
#ifndef NGLSINGLECOREAPPLICATION_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLSINGLECOREAPPLICATION_EXPORT
|
||||
# else
|
||||
# ifdef MAKE_NGLSINGLECOREAPPLICATION_LIB
|
||||
# define NGLSINGLECOREAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define NGLSINGLECOREAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLSINGLECOREAPPLICATION_EXPORT
|
||||
#else
|
||||
#ifdef MAKE_NGLSINGLECOREAPPLICATION_LIB
|
||||
#define NGLSINGLECOREAPPLICATION_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define NGLSINGLECOREAPPLICATION_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class NGLSINGLECOREAPPLICATION_EXPORT NGLSingleCoreApplication : public QtSingleCoreApplication, public NGL::LoggerHandler
|
||||
class NGLSINGLECOREAPPLICATION_EXPORT NGLSingleCoreApplication
|
||||
: public QtSingleCoreApplication
|
||||
, public NGL::LoggerHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
@@ -10,336 +10,344 @@
|
||||
|
||||
class BZip2IODevice::Private
|
||||
{
|
||||
public:
|
||||
Private(BZip2IODevice* parent_, QIODevice* dev, int bs)
|
||||
: parent(parent_), device(dev), iCurPos(0), iMaxBufSize(1024 * 1024), blocksize(bs), initialized(false),
|
||||
decomressStreamEnd(false)
|
||||
{
|
||||
buffer.resize(iMaxBufSize);
|
||||
}
|
||||
public:
|
||||
Private(BZip2IODevice *parent_, QIODevice *dev, int bs)
|
||||
: parent(parent_)
|
||||
, device(dev)
|
||||
, iCurPos(0)
|
||||
, iMaxBufSize(1024 * 1024)
|
||||
, blocksize(bs)
|
||||
, initialized(false)
|
||||
, decomressStreamEnd(false)
|
||||
{
|
||||
buffer.resize(iMaxBufSize);
|
||||
}
|
||||
|
||||
bool initializeCompress();
|
||||
qint64 doCompress(const char* in, qint64 iMaxLen);
|
||||
bool finishCompress();
|
||||
bool initializeDecompress();
|
||||
qint64 doDecompress(char* out, qint64 iMaxLen);
|
||||
bool finishDecompress();
|
||||
static QString bzipError2String(int errCode);
|
||||
bool initializeCompress();
|
||||
qint64 doCompress(const char *in, qint64 iMaxLen);
|
||||
bool finishCompress();
|
||||
bool initializeDecompress();
|
||||
qint64 doDecompress(char *out, qint64 iMaxLen);
|
||||
bool finishDecompress();
|
||||
static QString bzipError2String(int errCode);
|
||||
|
||||
QAtomicInt aborted{0};
|
||||
BZip2IODevice* parent;
|
||||
QIODevice* device;
|
||||
unsigned int iCurPos;
|
||||
unsigned int iMaxBufSize;
|
||||
unsigned int blocksize;
|
||||
bool initialized;
|
||||
bool decomressStreamEnd;
|
||||
QByteArray buffer;
|
||||
bz_stream stream;
|
||||
QAtomicInt aborted{0};
|
||||
BZip2IODevice *parent;
|
||||
QIODevice *device;
|
||||
unsigned int iCurPos;
|
||||
unsigned int iMaxBufSize;
|
||||
unsigned int blocksize;
|
||||
bool initialized;
|
||||
bool decomressStreamEnd;
|
||||
QByteArray buffer;
|
||||
bz_stream stream;
|
||||
};
|
||||
|
||||
bool BZip2IODevice::Private::initializeCompress()
|
||||
{
|
||||
if (initialized)
|
||||
return true;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
int blockSize = (blocksize > 0 && blocksize < 10) ? blocksize : 10;
|
||||
int ret = BZ2_bzCompressInit(&stream, blockSize, 0, 0);
|
||||
if (ret != BZ_OK)
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error initializing bzip2 %1").arg(bzipError2String(ret)));
|
||||
initialized = false;
|
||||
}
|
||||
else
|
||||
initialized = true;
|
||||
if (initialized)
|
||||
return true;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
int blockSize = (blocksize > 0 && blocksize < 10) ? blocksize : 10;
|
||||
int ret = BZ2_bzCompressInit(&stream, blockSize, 0, 0);
|
||||
if (ret != BZ_OK)
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error initializing bzip2 %1").arg(bzipError2String(ret)));
|
||||
initialized = false;
|
||||
}
|
||||
else
|
||||
initialized = true;
|
||||
|
||||
return initialized;
|
||||
return initialized;
|
||||
}
|
||||
|
||||
qint64 BZip2IODevice::Private::doCompress(const char* in, qint64 iMaxLen)
|
||||
qint64 BZip2IODevice::Private::doCompress(const char *in, qint64 iMaxLen)
|
||||
{
|
||||
if (!initialized)
|
||||
if (!initialized)
|
||||
{
|
||||
if (parent->errorString().isEmpty())
|
||||
parent->setErrorString(QLatin1String("Internal Error - bzip not initialized"));
|
||||
finishCompress();
|
||||
return -1;
|
||||
}
|
||||
if (iMaxLen > 2 * 1024 * 1024 * 1024LL)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Currently can't handle more than 2GB!"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
stream.next_in = const_cast<char *>(in);
|
||||
stream.avail_in = iMaxLen;
|
||||
|
||||
do
|
||||
{
|
||||
if (aborted)
|
||||
return 0;
|
||||
|
||||
stream.next_out = buffer.data();
|
||||
stream.avail_out = buffer.size();
|
||||
|
||||
const int ret = BZ2_bzCompress(&stream, BZ_RUN);
|
||||
if (ret != BZ_RUN_OK)
|
||||
{
|
||||
if (parent->errorString().isEmpty())
|
||||
parent->setErrorString(QLatin1String("Internal Error - bzip not initialized"));
|
||||
finishCompress();
|
||||
return -1;
|
||||
finishCompress();
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
return -1;
|
||||
}
|
||||
if (iMaxLen > 2 * 1024 * 1024 * 1024LL)
|
||||
int iBytesToWrite = buffer.size() - stream.avail_out;
|
||||
if (iBytesToWrite)
|
||||
{
|
||||
if (device->write(buffer.constData(), iBytesToWrite) != iBytesToWrite)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Currently can't handle more than 2GB!"));
|
||||
parent->setErrorString(QLatin1String("Error writing to QIODevice"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} while (stream.avail_in != 0);
|
||||
|
||||
stream.next_in = const_cast<char*>(in);
|
||||
stream.avail_in = iMaxLen;
|
||||
|
||||
do
|
||||
{
|
||||
if (aborted)
|
||||
return 0;
|
||||
|
||||
stream.next_out = buffer.data();
|
||||
stream.avail_out = buffer.size();
|
||||
|
||||
const int ret = BZ2_bzCompress(&stream, BZ_RUN);
|
||||
if (ret != BZ_RUN_OK)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
return -1;
|
||||
}
|
||||
int iBytesToWrite = buffer.size() - stream.avail_out;
|
||||
if (iBytesToWrite)
|
||||
{
|
||||
if (device->write(buffer.constData(), iBytesToWrite) != iBytesToWrite)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Error writing to QIODevice"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} while (stream.avail_in != 0);
|
||||
|
||||
return stream.next_in - in;
|
||||
return stream.next_in - in;
|
||||
}
|
||||
|
||||
bool BZip2IODevice::Private::finishCompress()
|
||||
{
|
||||
if (!initialized || aborted)
|
||||
return true;
|
||||
|
||||
int ret = -1;
|
||||
|
||||
do
|
||||
{
|
||||
stream.next_out = buffer.data();
|
||||
stream.avail_out = buffer.size();
|
||||
ret = BZ2_bzCompress(&stream, BZ_FINISH);
|
||||
if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
return false;
|
||||
}
|
||||
int iBytesToWrite = buffer.size() - stream.avail_out;
|
||||
if (device->write(buffer.constData(), iBytesToWrite) != iBytesToWrite)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Error writing to QIODevice"));
|
||||
return false;
|
||||
}
|
||||
} while (ret != BZ_STREAM_END);
|
||||
BZ2_bzCompressEnd(&stream);
|
||||
|
||||
initialized = false;
|
||||
if (!initialized || aborted)
|
||||
return true;
|
||||
|
||||
int ret = -1;
|
||||
|
||||
do
|
||||
{
|
||||
stream.next_out = buffer.data();
|
||||
stream.avail_out = buffer.size();
|
||||
ret = BZ2_bzCompress(&stream, BZ_FINISH);
|
||||
if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
return false;
|
||||
}
|
||||
int iBytesToWrite = buffer.size() - stream.avail_out;
|
||||
if (device->write(buffer.constData(), iBytesToWrite) != iBytesToWrite)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Error writing to QIODevice"));
|
||||
return false;
|
||||
}
|
||||
} while (ret != BZ_STREAM_END);
|
||||
BZ2_bzCompressEnd(&stream);
|
||||
|
||||
initialized = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BZip2IODevice::Private::initializeDecompress()
|
||||
{
|
||||
if (initialized)
|
||||
return true;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
int ret = BZ2_bzDecompressInit(&stream, 0, 0);
|
||||
if (ret != BZ_OK)
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error initializing bzip2: %1").arg(bzipError2String(ret)));
|
||||
initialized = false;
|
||||
}
|
||||
else
|
||||
initialized = true;
|
||||
decomressStreamEnd = false;
|
||||
return initialized;
|
||||
if (initialized)
|
||||
return true;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
int ret = BZ2_bzDecompressInit(&stream, 0, 0);
|
||||
if (ret != BZ_OK)
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error initializing bzip2: %1").arg(bzipError2String(ret)));
|
||||
initialized = false;
|
||||
}
|
||||
else
|
||||
initialized = true;
|
||||
decomressStreamEnd = false;
|
||||
return initialized;
|
||||
}
|
||||
|
||||
qint64 BZip2IODevice::Private::doDecompress(char* out, qint64 iMaxLen)
|
||||
qint64 BZip2IODevice::Private::doDecompress(char *out, qint64 iMaxLen)
|
||||
{
|
||||
int ret = -1;
|
||||
if (!initialized)
|
||||
{
|
||||
if (parent->errorString().isEmpty())
|
||||
parent->setErrorString(QLatin1String("Internal Error - bzip not initialized"));
|
||||
finishDecompress();
|
||||
return -1;
|
||||
}
|
||||
if (decomressStreamEnd)
|
||||
return 0;
|
||||
int ret = -1;
|
||||
if (!initialized)
|
||||
{
|
||||
if (parent->errorString().isEmpty())
|
||||
parent->setErrorString(QLatin1String("Internal Error - bzip not initialized"));
|
||||
finishDecompress();
|
||||
return -1;
|
||||
}
|
||||
if (decomressStreamEnd)
|
||||
return 0;
|
||||
|
||||
if (iMaxLen > 2 * 1024 * 1024 * 1024LL)
|
||||
if (iMaxLen > 2 * 1024 * 1024 * 1024LL)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Currently can't handle more than 2GB!"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
stream.next_out = out;
|
||||
stream.avail_out = iMaxLen;
|
||||
|
||||
do
|
||||
{
|
||||
if (ret != BZ_STREAM_END && stream.avail_in == 0)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Currently can't handle more than 2GB!"));
|
||||
qint64 iReadCnt = device->read(buffer.data(), buffer.size());
|
||||
if (iReadCnt <= 0)
|
||||
return -1;
|
||||
stream.next_in = buffer.data();
|
||||
stream.avail_in = iReadCnt;
|
||||
}
|
||||
|
||||
stream.next_out = out;
|
||||
stream.avail_out = iMaxLen;
|
||||
|
||||
do
|
||||
ret = BZ2_bzDecompress(&stream);
|
||||
if (ret != BZ_OK && ret != BZ_STREAM_END)
|
||||
{
|
||||
if (ret != BZ_STREAM_END && stream.avail_in == 0)
|
||||
{
|
||||
qint64 iReadCnt = device->read(buffer.data(), buffer.size());
|
||||
if (iReadCnt <= 0)
|
||||
return -1;
|
||||
stream.next_in = buffer.data();
|
||||
stream.avail_in = iReadCnt;
|
||||
}
|
||||
|
||||
ret = BZ2_bzDecompress(&stream);
|
||||
if (ret != BZ_OK && ret != BZ_STREAM_END)
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
finishDecompress();
|
||||
return -1;
|
||||
}
|
||||
} while (stream.avail_out != 0 && ret != BZ_STREAM_END);
|
||||
decomressStreamEnd = (ret == BZ_STREAM_END);
|
||||
return stream.next_out - out;
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
finishDecompress();
|
||||
return -1;
|
||||
}
|
||||
} while (stream.avail_out != 0 && ret != BZ_STREAM_END);
|
||||
decomressStreamEnd = (ret == BZ_STREAM_END);
|
||||
return stream.next_out - out;
|
||||
}
|
||||
|
||||
bool BZip2IODevice::Private::finishDecompress()
|
||||
{
|
||||
if (!initialized)
|
||||
return true;
|
||||
BZ2_bzDecompressEnd(&stream);
|
||||
|
||||
initialized = false;
|
||||
if (!initialized)
|
||||
return true;
|
||||
BZ2_bzDecompressEnd(&stream);
|
||||
|
||||
initialized = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
QString BZip2IODevice::Private::bzipError2String(int errCode)
|
||||
{
|
||||
switch (errCode)
|
||||
{
|
||||
case BZ_SEQUENCE_ERROR:
|
||||
return QLatin1String("Sequence error");
|
||||
case BZ_PARAM_ERROR:
|
||||
return QLatin1String("Parameter not correct");
|
||||
case BZ_MEM_ERROR:
|
||||
return QLatin1String("Memory allocation error");
|
||||
case BZ_DATA_ERROR:
|
||||
return QLatin1String("Invalid input data");
|
||||
case BZ_DATA_ERROR_MAGIC:
|
||||
return QLatin1String("Not a bzip2 file");
|
||||
case BZ_IO_ERROR:
|
||||
return QLatin1String("I/O error");
|
||||
case BZ_UNEXPECTED_EOF:
|
||||
return QLatin1String("Unexpected end of file");
|
||||
case BZ_OUTBUFF_FULL:
|
||||
return QLatin1String("Output buffer full");
|
||||
case BZ_CONFIG_ERROR:
|
||||
return QLatin1String("Wrong config parameter");
|
||||
};
|
||||
return QString::number(errCode);
|
||||
switch (errCode)
|
||||
{
|
||||
case BZ_SEQUENCE_ERROR:
|
||||
return QLatin1String("Sequence error");
|
||||
case BZ_PARAM_ERROR:
|
||||
return QLatin1String("Parameter not correct");
|
||||
case BZ_MEM_ERROR:
|
||||
return QLatin1String("Memory allocation error");
|
||||
case BZ_DATA_ERROR:
|
||||
return QLatin1String("Invalid input data");
|
||||
case BZ_DATA_ERROR_MAGIC:
|
||||
return QLatin1String("Not a bzip2 file");
|
||||
case BZ_IO_ERROR:
|
||||
return QLatin1String("I/O error");
|
||||
case BZ_UNEXPECTED_EOF:
|
||||
return QLatin1String("Unexpected end of file");
|
||||
case BZ_OUTBUFF_FULL:
|
||||
return QLatin1String("Output buffer full");
|
||||
case BZ_CONFIG_ERROR:
|
||||
return QLatin1String("Wrong config parameter");
|
||||
};
|
||||
return QString::number(errCode);
|
||||
}
|
||||
|
||||
BZip2IODevice::BZip2IODevice(QIODevice* dev, int blocksize) : d(new Private(this, dev, blocksize)) {}
|
||||
BZip2IODevice::BZip2IODevice(QIODevice *dev, int blocksize)
|
||||
: d(new Private(this, dev, blocksize))
|
||||
{
|
||||
}
|
||||
|
||||
BZip2IODevice::~BZip2IODevice()
|
||||
{
|
||||
close();
|
||||
delete d;
|
||||
close();
|
||||
delete d;
|
||||
}
|
||||
|
||||
void BZip2IODevice::setBufferSize(unsigned int size)
|
||||
{
|
||||
d->iMaxBufSize = size > 1024 ? size : 1024;
|
||||
d->buffer.resize(d->iMaxBufSize);
|
||||
d->iMaxBufSize = size > 1024 ? size : 1024;
|
||||
d->buffer.resize(d->iMaxBufSize);
|
||||
}
|
||||
|
||||
void BZip2IODevice::setBlockSize(unsigned int size)
|
||||
{
|
||||
if (isOpen())
|
||||
return;
|
||||
d->blocksize = size;
|
||||
if (isOpen())
|
||||
return;
|
||||
d->blocksize = size;
|
||||
}
|
||||
|
||||
bool BZip2IODevice::isSequential() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BZip2IODevice::open(OpenMode mode)
|
||||
{
|
||||
if ((mode & QIODevice::ReadWrite) == 0)
|
||||
if ((mode & QIODevice::ReadWrite) == 0)
|
||||
{
|
||||
setErrorString(QStringLiteral("Unsupported OpenMode %1").arg(static_cast<int>(mode)));
|
||||
return false;
|
||||
}
|
||||
if ((mode & QIODevice::ReadWrite) == QIODevice::ReadWrite)
|
||||
{
|
||||
setErrorString(QLatin1String("Can't read and write simultaniously"));
|
||||
return false;
|
||||
}
|
||||
if ((mode & QIODevice::ReadOnly) == QIODevice::ReadOnly)
|
||||
{
|
||||
if (!d->device)
|
||||
{
|
||||
setErrorString(QStringLiteral("Unsupported OpenMode %1").arg(static_cast<int>(mode)));
|
||||
return false;
|
||||
setErrorString(QLatin1String("No QIODevice for reading available"));
|
||||
return false;
|
||||
}
|
||||
if ((mode & QIODevice::ReadWrite) == QIODevice::ReadWrite)
|
||||
if ((d->device->openMode() & QIODevice::ReadOnly) == 0)
|
||||
{
|
||||
setErrorString(QLatin1String("Can't read and write simultaniously"));
|
||||
return false;
|
||||
setErrorString(QLatin1String("QIODevice not opened for reading"));
|
||||
return false;
|
||||
}
|
||||
if ((mode & QIODevice::ReadOnly) == QIODevice::ReadOnly)
|
||||
if (!d->initializeDecompress())
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!d->device)
|
||||
{
|
||||
if (!d->device)
|
||||
{
|
||||
setErrorString(QLatin1String("No QIODevice for reading available"));
|
||||
return false;
|
||||
}
|
||||
if ((d->device->openMode() & QIODevice::ReadOnly) == 0)
|
||||
{
|
||||
setErrorString(QLatin1String("QIODevice not opened for reading"));
|
||||
return false;
|
||||
}
|
||||
if (!d->initializeDecompress())
|
||||
return false;
|
||||
setErrorString(QLatin1String("No QIODevice for writing available"));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if ((d->device->openMode() & QIODevice::WriteOnly) == 0)
|
||||
{
|
||||
if (!d->device)
|
||||
{
|
||||
setErrorString(QLatin1String("No QIODevice for writing available"));
|
||||
return false;
|
||||
}
|
||||
if ((d->device->openMode() & QIODevice::WriteOnly) == 0)
|
||||
{
|
||||
setErrorString(QLatin1String("QIODevice not opened for writing"));
|
||||
return false;
|
||||
}
|
||||
if (!d->initializeCompress())
|
||||
return false;
|
||||
setErrorString(QLatin1String("QIODevice not opened for writing"));
|
||||
return false;
|
||||
}
|
||||
setErrorString(QString());
|
||||
setOpenMode(mode);
|
||||
return QIODevice::open(mode);
|
||||
if (!d->initializeCompress())
|
||||
return false;
|
||||
}
|
||||
setErrorString(QString());
|
||||
setOpenMode(mode);
|
||||
return QIODevice::open(mode);
|
||||
}
|
||||
|
||||
void BZip2IODevice::abort()
|
||||
{
|
||||
d->aborted = 1;
|
||||
d->aborted = 1;
|
||||
}
|
||||
|
||||
void BZip2IODevice::close()
|
||||
{
|
||||
if (!isOpen())
|
||||
return;
|
||||
if ((openMode() & QIODevice::ReadOnly) == QIODevice::ReadOnly)
|
||||
d->finishDecompress();
|
||||
else
|
||||
d->finishCompress();
|
||||
QIODevice::close();
|
||||
if (!isOpen())
|
||||
return;
|
||||
if ((openMode() & QIODevice::ReadOnly) == QIODevice::ReadOnly)
|
||||
d->finishDecompress();
|
||||
else
|
||||
d->finishCompress();
|
||||
QIODevice::close();
|
||||
}
|
||||
|
||||
bool BZip2IODevice::atEnd() const
|
||||
{
|
||||
if (!d->device)
|
||||
return true;
|
||||
return d->device->atEnd() && d->decomressStreamEnd && QIODevice::atEnd();
|
||||
if (!d->device)
|
||||
return true;
|
||||
return d->device->atEnd() && d->decomressStreamEnd && QIODevice::atEnd();
|
||||
}
|
||||
|
||||
qint64 BZip2IODevice::readData(char* data, qint64 maxSize)
|
||||
qint64 BZip2IODevice::readData(char *data, qint64 maxSize)
|
||||
{
|
||||
return d->doDecompress(data, maxSize);
|
||||
return d->doDecompress(data, maxSize);
|
||||
}
|
||||
|
||||
qint64 BZip2IODevice::writeData(const char* data, qint64 maxSize)
|
||||
qint64 BZip2IODevice::writeData(const char *data, qint64 maxSize)
|
||||
{
|
||||
return d->doCompress(data, maxSize);
|
||||
return d->doCompress(data, maxSize);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Executable → Regular
+29
-14
@@ -1,8 +1,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef BZIP2IODEVICE_H
|
||||
#define BZIP2IODEVICE_H
|
||||
|
||||
@@ -14,26 +12,24 @@
|
||||
class BZip2IODevice : public QIODevice
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
|
||||
BZip2IODevice(QIODevice *dev, int blocksize = 5);
|
||||
virtual ~BZip2IODevice();
|
||||
|
||||
void abort();
|
||||
void setBufferSize(unsigned int size);
|
||||
void setBlockSize(unsigned int size);
|
||||
void setBufferSize(unsigned int size);
|
||||
void setBlockSize(unsigned int size);
|
||||
|
||||
|
||||
|
||||
virtual bool isSequential() const;
|
||||
virtual bool open(OpenMode mode);
|
||||
virtual void close();
|
||||
virtual bool atEnd() const;
|
||||
|
||||
protected:
|
||||
virtual qint64 readData(char *data, qint64 maxSize);
|
||||
virtual qint64 writeData(const char *data, qint64 maxSize);
|
||||
private:
|
||||
|
||||
private:
|
||||
class Private;
|
||||
friend class Private;
|
||||
Private *const d;
|
||||
@@ -44,19 +40,38 @@ private:
|
||||
class BZip2IODevice : public QIODevice
|
||||
{
|
||||
public:
|
||||
BZip2IODevice(QIODevice *dev, int blocksize = 5) { Q_UNUSED(dev) Q_UNUSED(blocksize) }
|
||||
BZip2IODevice(QIODevice *dev, int blocksize = 5)
|
||||
{
|
||||
Q_UNUSED(dev)
|
||||
Q_UNUSED(blocksize)
|
||||
}
|
||||
virtual ~BZip2IODevice() {}
|
||||
void abort() {}
|
||||
void setBufferSize(unsigned int size) { Q_UNUSED(size) }
|
||||
void setBlockSize(unsigned int size) { Q_UNUSED(size) }
|
||||
virtual bool isSequential() const { return true; }
|
||||
virtual bool open(OpenMode mode) { Q_UNUSED(mode) return false; }
|
||||
virtual bool open(OpenMode mode)
|
||||
{
|
||||
Q_UNUSED(mode)
|
||||
return false;
|
||||
}
|
||||
virtual void close() {}
|
||||
virtual bool atEnd() const { return true; }
|
||||
|
||||
protected:
|
||||
virtual qint64 readData(char *data, qint64 maxSize) { Q_UNUSED(data) Q_UNUSED(maxSize) return -1; }
|
||||
virtual qint64 writeData(const char *data, qint64 maxSize) { Q_UNUSED(data) Q_UNUSED(maxSize) return -1; }
|
||||
virtual qint64 readData(char *data, qint64 maxSize)
|
||||
{
|
||||
Q_UNUSED(data)
|
||||
Q_UNUSED(maxSize)
|
||||
return -1;
|
||||
}
|
||||
virtual qint64 writeData(const char *data, qint64 maxSize)
|
||||
{
|
||||
Q_UNUSED(data)
|
||||
Q_UNUSED(maxSize)
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -21,22 +21,22 @@
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
Compress::Compress(QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("nglcompress"))
|
||||
, m_u2_memFiles()
|
||||
, m_aborted(0)
|
||||
{
|
||||
Compress::Compress(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("nglcompress"))
|
||||
, m_u2_memFiles()
|
||||
, m_aborted(0)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "c_tor";
|
||||
|
||||
QTimer* t = new QTimer(this);
|
||||
QTimer *t = new QTimer(this);
|
||||
t->setInterval(1000);
|
||||
connect(t, &QTimer::timeout, this, []() { qWarning() << "still alive ..."; });
|
||||
t->start();
|
||||
}
|
||||
}
|
||||
|
||||
Compress::~Compress()
|
||||
{
|
||||
Compress::~Compress()
|
||||
{
|
||||
qWarning() << "## COMPRESS DTOR!!!!";
|
||||
|
||||
DEBUG_LOG(m_logger) << "~";
|
||||
@@ -44,10 +44,10 @@ Compress::~Compress()
|
||||
abort();
|
||||
m_future.waitForFinished();
|
||||
DEBUG_LOG(m_logger) << "~ finished";
|
||||
}
|
||||
}
|
||||
|
||||
void Compress::abort()
|
||||
{
|
||||
void Compress::abort()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "ABORT";
|
||||
|
||||
m_aborted = 1;
|
||||
@@ -55,29 +55,31 @@ void Compress::abort()
|
||||
|
||||
if (m_currentTarFilter != nullptr)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "aborting tar";
|
||||
m_currentTarFilter->abort();
|
||||
DEBUG_LOG(m_logger) << "aborting tar";
|
||||
m_currentTarFilter->abort();
|
||||
}
|
||||
|
||||
if (m_currentBzipDevice != nullptr)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "aborting bzip";
|
||||
m_currentBzipDevice->abort();
|
||||
DEBUG_LOG(m_logger) << "aborting bzip";
|
||||
m_currentBzipDevice->abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Compress::compress(QIODevice* out, const QString& filesRootDir, const QVector<FileInformations>& files,
|
||||
const QVector<FileInformations>& memFiles, const QString& destRootDir)
|
||||
{
|
||||
void Compress::compress(QIODevice *out,
|
||||
const QString &filesRootDir,
|
||||
const QVector<FileInformations> &files,
|
||||
const QVector<FileInformations> &memFiles,
|
||||
const QString &destRootDir)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "compress #2";
|
||||
reset();
|
||||
setupFutureWatcher(QtConcurrent::run([this, out, filesRootDir, files, memFiles, destRootDir]() {
|
||||
return this->_compress(out, filesRootDir, files, memFiles, destRootDir);
|
||||
}));
|
||||
}
|
||||
setupFutureWatcher(
|
||||
QtConcurrent::run([this, out, filesRootDir, files, memFiles, destRootDir]() { return this->_compress(out, filesRootDir, files, memFiles, destRootDir); }));
|
||||
}
|
||||
|
||||
void Compress::compress(QIODevice* out, const QString& sourceDir, const QString& destRootDir)
|
||||
{
|
||||
void Compress::compress(QIODevice *out, const QString &sourceDir, const QString &destRootDir)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "compress #1 source dir: " << sourceDir << ", destRootDir: " << destRootDir;
|
||||
reset();
|
||||
|
||||
@@ -85,40 +87,44 @@ void Compress::compress(QIODevice* out, const QString& sourceDir, const QString&
|
||||
|
||||
int len = sourceDir.length();
|
||||
if (!sourceDir.endsWith(QLatin1Char('/')))
|
||||
len += 1;
|
||||
for (auto& fi : inFiles)
|
||||
len += 1;
|
||||
for (auto &fi : inFiles)
|
||||
{
|
||||
fi.inputFileName = fi.inputFileName.mid(len);
|
||||
fi.bAbsInputPath = false;
|
||||
DEBUG_LOG(m_logger) << "fi: ifm = " << fi.inputFileName << ", abs = " << fi.bAbsInputPath;
|
||||
fi.inputFileName = fi.inputFileName.mid(len);
|
||||
fi.bAbsInputPath = false;
|
||||
DEBUG_LOG(m_logger) << "fi: ifm = " << fi.inputFileName << ", abs = " << fi.bAbsInputPath;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "FI list size: " << inFiles.count();
|
||||
|
||||
compress(out, sourceDir, inFiles, {}, destRootDir);
|
||||
}
|
||||
}
|
||||
|
||||
bool Compress::_compress(QIODevice* output, const QString& filesRootDir, const QVector<FileInformations>& files,
|
||||
const QVector<FileInformations>& memFiles, const QString& _destRootDir)
|
||||
{
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr, [this](int*) {
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #1";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
bool Compress::_compress(QIODevice *output,
|
||||
const QString &filesRootDir,
|
||||
const QVector<FileInformations> &files,
|
||||
const QVector<FileInformations> &memFiles,
|
||||
const QString &_destRootDir)
|
||||
{
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr,
|
||||
[this](int *)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #1";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
(void)invalidatePointersOnScopeLeave;
|
||||
|
||||
if (!output || !output->isWritable())
|
||||
{
|
||||
m_lastError = tr("Device is not writeable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
;
|
||||
m_lastError = tr("Device is not writeable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString destRootDir =
|
||||
_destRootDir.endsWith(QLatin1Char('/')) ? _destRootDir : _destRootDir + QLatin1Char('/');
|
||||
const QString destRootDir = _destRootDir.endsWith(QLatin1Char('/')) ? _destRootDir : _destRootDir + QLatin1Char('/');
|
||||
|
||||
const qint64 maxCount = files.count() + memFiles.count();
|
||||
qint64 count = 0;
|
||||
@@ -130,32 +136,31 @@ bool Compress::_compress(QIODevice* output, const QString& filesRootDir, const Q
|
||||
|
||||
if (!bzip2.open(QIODevice::WriteOnly))
|
||||
{
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
qint64 bytesTotal = 0;
|
||||
for (const FileInformations& file : std::as_const(files))
|
||||
for (const FileInformations &file : std::as_const(files))
|
||||
{
|
||||
if (m_aborted)
|
||||
return false;
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
const QString in =
|
||||
file.bAbsInputPath ? file.inputFileName : filesRootDir + QLatin1Char('/') + file.inputFileName;
|
||||
const QFileInfo fi(in);
|
||||
const QString in = file.bAbsInputPath ? file.inputFileName : filesRootDir + QLatin1Char('/') + file.inputFileName;
|
||||
const QFileInfo fi(in);
|
||||
|
||||
bytesTotal += fi.size();
|
||||
bytesTotal += fi.size();
|
||||
}
|
||||
|
||||
qint64 currentFileSize = 0;
|
||||
QString currentFileName;
|
||||
auto readCallback = [this, &maxCount, &count, ¤tFileSize, ¤tFileName, &bytesTotal](const qint64 iSize) {
|
||||
DEBUG_LOG(m_logger) << "readCallback: maxCount = " << maxCount << ", count = " << count
|
||||
<< ", currentFileSize = " << currentFileSize << ", currentFileName = " << currentFileName
|
||||
<< ", iSize = " << iSize;
|
||||
emit compressInfoEx(maxCount, count, currentFileSize, (currentFileSize - iSize), currentFileName, bytesTotal);
|
||||
auto readCallback = [this, &maxCount, &count, ¤tFileSize, ¤tFileName, &bytesTotal](const qint64 iSize)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "readCallback: maxCount = " << maxCount << ", count = " << count << ", currentFileSize = " << currentFileSize
|
||||
<< ", currentFileName = " << currentFileName << ", iSize = " << iSize;
|
||||
emit compressInfoEx(maxCount, count, currentFileSize, (currentFileSize - iSize), currentFileName, bytesTotal);
|
||||
};
|
||||
|
||||
TarFilter tf(&bzip2, readCallback);
|
||||
@@ -164,96 +169,94 @@ bool Compress::_compress(QIODevice* output, const QString& filesRootDir, const Q
|
||||
QString curPath;
|
||||
|
||||
DEBUG_LOG(m_logger) << "prepairing tar filter";
|
||||
for (const QString& path : paths)
|
||||
for (const QString &path : paths)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "path = " << path;
|
||||
if (m_aborted)
|
||||
return false;
|
||||
DEBUG_LOG(m_logger) << "path = " << path;
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
if (curPath.isEmpty())
|
||||
curPath = path + QLatin1Char('/');
|
||||
else
|
||||
curPath += path + QLatin1Char('/');
|
||||
if (curPath.isEmpty())
|
||||
curPath = path + QLatin1Char('/');
|
||||
else
|
||||
curPath += path + QLatin1Char('/');
|
||||
|
||||
DEBUG_LOG(m_logger) << "curPath = " << curPath << ", filesRootDir.isEmpty() = " << filesRootDir.isEmpty();
|
||||
DEBUG_LOG(m_logger) << "curPath = " << curPath << ", filesRootDir.isEmpty() = " << filesRootDir.isEmpty();
|
||||
|
||||
if (filesRootDir.isEmpty())
|
||||
if (filesRootDir.isEmpty())
|
||||
{
|
||||
if (!tf.addData(curPath, QByteArray(), true))
|
||||
{
|
||||
if (!tf.addData(curPath, QByteArray(), true))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!tf.addFile(filesRootDir, curPath))
|
||||
{
|
||||
if (!tf.addFile(filesRootDir, curPath))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_c_sizeInfo.realSize = 0;
|
||||
for (const FileInformations& file : std::as_const(files))
|
||||
for (const FileInformations &file : std::as_const(files))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "file = " << file.inputFileName;
|
||||
emit compressInfo(maxCount, ++count, file.inputFileName);
|
||||
DEBUG_LOG(m_logger) << "file = " << file.inputFileName;
|
||||
emit compressInfo(maxCount, ++count, file.inputFileName);
|
||||
|
||||
if (m_aborted)
|
||||
return false;
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
QString in = file.bAbsInputPath ? file.inputFileName : filesRootDir + QLatin1Char('/') + file.inputFileName;
|
||||
QString out = destRootDir + (file.outputFileName.isEmpty() ? file.inputFileName : file.outputFileName);
|
||||
QString in = file.bAbsInputPath ? file.inputFileName : filesRootDir + QLatin1Char('/') + file.inputFileName;
|
||||
QString out = destRootDir + (file.outputFileName.isEmpty() ? file.inputFileName : file.outputFileName);
|
||||
|
||||
DEBUG_LOG(m_logger) << "in = " << in << ", out = " << out;
|
||||
DEBUG_LOG(m_logger) << "in = " << in << ", out = " << out;
|
||||
|
||||
QFileInfo fi(in);
|
||||
QFileInfo fi(in);
|
||||
|
||||
currentFileName = fi.fileName();
|
||||
currentFileSize = fi.size();
|
||||
m_c_sizeInfo.realSize += currentFileSize;
|
||||
currentFileName = fi.fileName();
|
||||
currentFileSize = fi.size();
|
||||
m_c_sizeInfo.realSize += currentFileSize;
|
||||
|
||||
DEBUG_LOG(m_logger) << "currentFileName = " << currentFileName << ", currentFileSize = " << currentFileSize
|
||||
<< "m_c_sizeInfo.realSize" << m_c_sizeInfo.realSize;
|
||||
DEBUG_LOG(m_logger) << "currentFileName = " << currentFileName << ", currentFileSize = " << currentFileSize << "m_c_sizeInfo.realSize" << m_c_sizeInfo.realSize;
|
||||
|
||||
if (!tf.addFile(in, out))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
if (!tf.addFile(in, out))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (const FileInformations& file : std::as_const(memFiles))
|
||||
for (const FileInformations &file : std::as_const(memFiles))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "(mem) file = " << file.inputFileName;
|
||||
emit compressInfo(maxCount, ++count, file.inputFileName);
|
||||
DEBUG_LOG(m_logger) << "(mem) file = " << file.inputFileName;
|
||||
emit compressInfo(maxCount, ++count, file.inputFileName);
|
||||
|
||||
if (m_aborted)
|
||||
return false;
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
currentFileName = file.inputFileName;
|
||||
currentFileSize = file.fileData.size();
|
||||
m_c_sizeInfo.compressedSize += currentFileSize;
|
||||
currentFileName = file.inputFileName;
|
||||
currentFileSize = file.fileData.size();
|
||||
m_c_sizeInfo.compressedSize += currentFileSize;
|
||||
|
||||
DEBUG_LOG(m_logger) << "(mem) currentFileName = " << currentFileName
|
||||
<< ", currentFileSize = " << currentFileSize << "m_c_sizeInfo.realSize"
|
||||
<< m_c_sizeInfo.realSize;
|
||||
DEBUG_LOG(m_logger) << "(mem) currentFileName = " << currentFileName << ", currentFileSize = " << currentFileSize << "m_c_sizeInfo.realSize"
|
||||
<< m_c_sizeInfo.realSize;
|
||||
|
||||
if (!tf.addData(file.inputFileName, file.fileData))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
if (!tf.addData(file.inputFileName, file.fileData))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "writing eos";
|
||||
@@ -270,42 +273,44 @@ bool Compress::_compress(QIODevice* output, const QString& filesRootDir, const Q
|
||||
DEBUG_LOG(m_logger) << "DONE!";
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void Compress::uncompress(QIODevice* in, const QString& outDir)
|
||||
{
|
||||
void Compress::uncompress(QIODevice *in, const QString &outDir)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "uncompress #1";
|
||||
reset();
|
||||
setupFutureWatcher(QtConcurrent::run([this, in, outDir]() { return this->_uncompressDirectory(in, outDir); }));
|
||||
}
|
||||
}
|
||||
|
||||
bool Compress::_uncompressDirectory(QIODevice* input, const QString& outDir)
|
||||
{
|
||||
bool Compress::_uncompressDirectory(QIODevice *input, const QString &outDir)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "_uncompressDirectory";
|
||||
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr, [this](int*) {
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #2";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr,
|
||||
[this](int *)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #2";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
(void)invalidatePointersOnScopeLeave;
|
||||
|
||||
if (!input || !input->isReadable())
|
||||
{
|
||||
m_lastError = tr("Device is not readable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
m_lastError = tr("Device is not readable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
BZip2IODevice bzip2(input, 9);
|
||||
m_currentBzipDevice = &bzip2;
|
||||
if (!bzip2.open(QIODevice::ReadOnly))
|
||||
{
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
TarFilter tf(&bzip2);
|
||||
@@ -317,92 +322,94 @@ bool Compress::_uncompressDirectory(QIODevice* input, const QString& outDir)
|
||||
|
||||
while (tf.getData(tfi))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "tfi.fileName = " << tfi.fileName;
|
||||
emit uncompressInfo(input->size(), input->pos(), tfi.fileName);
|
||||
if (m_aborted)
|
||||
return false;
|
||||
DEBUG_LOG(m_logger) << "tfi.fileName = " << tfi.fileName;
|
||||
emit uncompressInfo(input->size(), input->pos(), tfi.fileName);
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
QString path = outDir + QLatin1Char('/') + tfi.fileName;
|
||||
DEBUG_LOG(m_logger) << "path = " << path;
|
||||
if (tfi.fileType == TarFilter::directory)
|
||||
QString path = outDir + QLatin1Char('/') + tfi.fileName;
|
||||
DEBUG_LOG(m_logger) << "path = " << path;
|
||||
if (tfi.fileType == TarFilter::directory)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "tfi.fileType == TarFilter::directory";
|
||||
if (!dir.exists(path) && !dir.mkpath(path))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "tfi.fileType == TarFilter::directory";
|
||||
if (!dir.exists(path) && !dir.mkpath(path))
|
||||
{
|
||||
m_lastError = tr("Error creating directory %1").arg(outDir);
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
m_lastError = tr("Error creating directory %1").arg(outDir);
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
QString pathName = QFileInfo(path).absolutePath();
|
||||
if (!dir.exists(pathName) && !dir.mkpath(pathName))
|
||||
{
|
||||
m_lastError = tr("Error creating directory %1").arg(pathName);
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
QString pathName = QFileInfo(path).absolutePath();
|
||||
if (!dir.exists(pathName) && !dir.mkpath(pathName))
|
||||
{
|
||||
m_lastError = tr("Error creating directory %1").arg(pathName);
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
QFile f(path);
|
||||
if (!f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
m_lastError = tr("Error opening %1 for writing (%2)").arg(path, f.errorString());
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!tf.getData(&f))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
QFile f(path);
|
||||
if (!f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
m_lastError = tr("Error opening %1 for writing (%2)").arg(path, f.errorString());
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!tf.getData(&f))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "uncompress done!";
|
||||
m_success = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void Compress::uncompress(QIODevice* in)
|
||||
{
|
||||
void Compress::uncompress(QIODevice *in)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "uncompress #2!";
|
||||
reset();
|
||||
setupFutureWatcher(QtConcurrent::run([this, in]() { return this->_uncompressBuffer(in); }));
|
||||
}
|
||||
}
|
||||
|
||||
bool Compress::_uncompressBuffer(QIODevice* input)
|
||||
{
|
||||
bool Compress::_uncompressBuffer(QIODevice *input)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "uncompressBuffer";
|
||||
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr, [this](int*) {
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #2";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr,
|
||||
[this](int *)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #2";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
(void)invalidatePointersOnScopeLeave;
|
||||
|
||||
if (!input->isReadable())
|
||||
{
|
||||
m_lastError = tr("Device is not readable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
m_lastError = tr("Device is not readable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
BZip2IODevice bzip2(input, 9);
|
||||
m_currentBzipDevice = &bzip2;
|
||||
if (!bzip2.open(QIODevice::ReadOnly))
|
||||
{
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
TarFilter tf(&bzip2);
|
||||
@@ -410,71 +417,71 @@ bool Compress::_uncompressBuffer(QIODevice* input)
|
||||
TarFilter::FileInformations tfi;
|
||||
while (tf.getData(tfi))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "tfi.fileName = " << tfi.fileName;
|
||||
emit uncompressInfo(input->size(), input->pos(), tfi.fileName);
|
||||
if (m_aborted)
|
||||
return false;
|
||||
DEBUG_LOG(m_logger) << "tfi.fileName = " << tfi.fileName;
|
||||
emit uncompressInfo(input->size(), input->pos(), tfi.fileName);
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
FileInformations fi;
|
||||
fi.outputFileName = tfi.fileName;
|
||||
FileInformations fi;
|
||||
fi.outputFileName = tfi.fileName;
|
||||
|
||||
DEBUG_LOG(m_logger) << "fi.outputFileName = " << fi.outputFileName;
|
||||
DEBUG_LOG(m_logger) << "fi.outputFileName = " << fi.outputFileName;
|
||||
|
||||
if (tfi.fileType == TarFilter::directory)
|
||||
if (tfi.fileType == TarFilter::directory)
|
||||
{
|
||||
fi.outputFileName += QLatin1Char('/');
|
||||
DEBUG_LOG(m_logger) << "> fi.outputFileName = " << fi.outputFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "stuff";
|
||||
|
||||
QBuffer buf(&fi.fileData);
|
||||
if (!buf.open(QIODevice::WriteOnly))
|
||||
{
|
||||
fi.outputFileName += QLatin1Char('/');
|
||||
DEBUG_LOG(m_logger) << "> fi.outputFileName = " << fi.outputFileName;
|
||||
m_lastError = tr("Error opening buffer for writing (%1)").arg(buf.errorString());
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if (!tf.getData(&buf))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "stuff";
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
QBuffer buf(&fi.fileData);
|
||||
if (!buf.open(QIODevice::WriteOnly))
|
||||
{
|
||||
m_lastError = tr("Error opening buffer for writing (%1)").arg(buf.errorString());
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!tf.getData(&buf))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
fi.bAbsInputPath = fi.outputFileName.startsWith(QLatin1Char('/'));
|
||||
DEBUG_LOG(m_logger) << "added fi.bAbsInputPath = " << fi.bAbsInputPath;
|
||||
m_u2_memFiles += fi;
|
||||
fi.bAbsInputPath = fi.outputFileName.startsWith(QLatin1Char('/'));
|
||||
DEBUG_LOG(m_logger) << "added fi.bAbsInputPath = " << fi.bAbsInputPath;
|
||||
m_u2_memFiles += fi;
|
||||
}
|
||||
|
||||
m_success = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Compress::success() const
|
||||
{
|
||||
bool Compress::success() const
|
||||
{
|
||||
|
||||
ERROR_LOG(m_logger) << "success? " << (m_future.isFinished() && !m_future.isCanceled() && m_success);
|
||||
ERROR_LOG(m_logger) << "success details: "
|
||||
<< "success m_future.isFinished() = " << (m_future.isFinished())
|
||||
<< " !m_future.isCanceled() = " << !m_future.isCanceled() << " m_success = " << m_success;
|
||||
<< "success m_future.isFinished() = " << (m_future.isFinished()) << " !m_future.isCanceled() = " << !m_future.isCanceled()
|
||||
<< " m_success = " << m_success;
|
||||
return (m_future.isFinished() && !m_future.isCanceled() && m_success);
|
||||
}
|
||||
}
|
||||
|
||||
bool Compress::waitForFinished()
|
||||
{
|
||||
bool Compress::waitForFinished()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "waitForFinished...";
|
||||
m_future.waitForFinished();
|
||||
DEBUG_LOG(m_logger) << "waitForFinished... done!";
|
||||
return success();
|
||||
}
|
||||
}
|
||||
|
||||
QVector<Compress::FileInformations> Compress::directoryFileList(const QString& dir, bool recursive)
|
||||
{
|
||||
QVector<Compress::FileInformations> Compress::directoryFileList(const QString &dir, bool recursive)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "directoryFileList";
|
||||
|
||||
QVector<FileInformations> sl_absolute;
|
||||
@@ -482,28 +489,28 @@ QVector<Compress::FileInformations> Compress::directoryFileList(const QString& d
|
||||
|
||||
if (d.exists())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "exists";
|
||||
const auto entries = d.entryList(QDir::Files);
|
||||
sl_absolute.reserve(sl_absolute.size() + entries.size());
|
||||
for (const QString& entry : entries)
|
||||
sl_absolute << FileInformations(QFileInfo(d, entry).absoluteFilePath(), true);
|
||||
DEBUG_LOG(m_logger) << "exists";
|
||||
const auto entries = d.entryList(QDir::Files);
|
||||
sl_absolute.reserve(sl_absolute.size() + entries.size());
|
||||
for (const QString &entry : entries)
|
||||
sl_absolute << FileInformations(QFileInfo(d, entry).absoluteFilePath(), true);
|
||||
}
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "recursive";
|
||||
const auto entries = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
sl_absolute.reserve(sl_absolute.size() + entries.size());
|
||||
for (const QString& s : entries)
|
||||
sl_absolute << directoryFileList(dir + QLatin1Char('/') + s, true);
|
||||
DEBUG_LOG(m_logger) << "recursive";
|
||||
const auto entries = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
sl_absolute.reserve(sl_absolute.size() + entries.size());
|
||||
for (const QString &s : entries)
|
||||
sl_absolute << directoryFileList(dir + QLatin1Char('/') + s, true);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "done";
|
||||
return sl_absolute;
|
||||
}
|
||||
}
|
||||
|
||||
void Compress::reset()
|
||||
{
|
||||
void Compress::reset()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "reset";
|
||||
m_u2_memFiles.clear();
|
||||
|
||||
@@ -513,19 +520,18 @@ void Compress::reset()
|
||||
m_c_sizeInfo.compressedSize = 0;
|
||||
|
||||
m_success = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Compress::setupFutureWatcher(const QFuture<bool>& future)
|
||||
{
|
||||
void Compress::setupFutureWatcher(const QFuture<bool> &future)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "setupFutureWatcher";
|
||||
m_future = future;
|
||||
QFutureWatcher<bool>* fw = new QFutureWatcher<bool>(this);
|
||||
QFutureWatcher<bool> *fw = new QFutureWatcher<bool>(this);
|
||||
QObject::connect(fw, &QObject::destroyed, this, [this]() { DEBUG_LOG(m_logger) << "Future Watcher destroyed"; });
|
||||
QObject::connect(fw, &QFutureWatcher<bool>::finished, this, &Compress::finished);
|
||||
QObject::connect(fw, &QFutureWatcher<bool>::finished, fw, &QObject::deleteLater);
|
||||
QObject::connect(fw, &QFutureWatcher<bool>::finished, fw,
|
||||
[this]() { DEBUG_LOG(m_logger) << "Future Watcher about to be deleted"; });
|
||||
QObject::connect(fw, &QFutureWatcher<bool>::finished, fw, [this]() { DEBUG_LOG(m_logger) << "Future Watcher about to be deleted"; });
|
||||
fw->setFuture(m_future);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NGL
|
||||
Executable → Regular
+104
-114
@@ -19,122 +19,112 @@ class BZip2IODevice;
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class NGLCOMPRESSION_EXPORT Compress : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
struct FileInformations
|
||||
class NGLCOMPRESSION_EXPORT Compress : public QObject
|
||||
{
|
||||
QString inputFileName;
|
||||
QString outputFileName;
|
||||
QByteArray fileData;
|
||||
bool bAbsInputPath = true;
|
||||
FileInformations() = default;
|
||||
Q_OBJECT
|
||||
public:
|
||||
struct FileInformations
|
||||
{
|
||||
QString inputFileName;
|
||||
QString outputFileName;
|
||||
QByteArray fileData;
|
||||
bool bAbsInputPath = true;
|
||||
FileInformations() = default;
|
||||
|
||||
FileInformations(const QString &name, bool isAbsolute)
|
||||
: inputFileName(name)
|
||||
, bAbsInputPath(isAbsolute)
|
||||
{}
|
||||
FileInformations(const QString &name, bool isAbsolute)
|
||||
: inputFileName(name)
|
||||
, bAbsInputPath(isAbsolute)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct FileSizeInfo
|
||||
{
|
||||
qint64 realSize = 0;
|
||||
qint64 compressedSize = 0;
|
||||
};
|
||||
|
||||
|
||||
explicit Compress(QObject *parent = nullptr);
|
||||
|
||||
~Compress();
|
||||
|
||||
|
||||
QVector<FileInformations> getMemFiles() const { return m_u2_memFiles; }
|
||||
|
||||
|
||||
FileSizeInfo getFileSizeInfo() const { return m_c_sizeInfo; }
|
||||
|
||||
|
||||
bool success() const;
|
||||
|
||||
|
||||
void compress(QIODevice *out,
|
||||
const QString &sourceRootDir,
|
||||
const QVector<FileInformations> &files,
|
||||
const QVector<FileInformations> &memFiles,
|
||||
const QString &destRootDir);
|
||||
|
||||
|
||||
void compress(QIODevice *out, const QString &sourceDir, const QString &destRootDir);
|
||||
|
||||
|
||||
void uncompress(QIODevice *in, const QString &outDir);
|
||||
|
||||
|
||||
void uncompress(QIODevice *in);
|
||||
|
||||
|
||||
QString lastError() const { return m_lastError; }
|
||||
|
||||
|
||||
bool waitForFinished();
|
||||
|
||||
public Q_SLOTS:
|
||||
void abort();
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
|
||||
void uncompressInfo(qint64 totalSize, qint64 curPos, const QString &curName);
|
||||
|
||||
|
||||
void compressInfo(qint64 totalFiles, qint64 curFile, const QString &curName);
|
||||
void compressInfoEx(qint64 totalFiles, qint64 curFile, qint64 totalSize, qint64 curPos, const QString &curName, const qint64 bytesTotal);
|
||||
|
||||
|
||||
void error(const QString &errorString);
|
||||
|
||||
|
||||
void finished();
|
||||
|
||||
private:
|
||||
NGL::INGLLogger &m_logger;
|
||||
bool _compress(QIODevice *output,
|
||||
const QString &filesRootDir,
|
||||
const QVector<FileInformations> &files,
|
||||
const QVector<FileInformations> &memFiles,
|
||||
const QString &_destRootDir);
|
||||
bool _uncompressDirectory(QIODevice *input, const QString &outDir);
|
||||
bool _uncompressBuffer(QIODevice *input);
|
||||
|
||||
void reset();
|
||||
void setupFutureWatcher(const QFuture<bool> &future);
|
||||
|
||||
QVector<FileInformations> directoryFileList(const QString &dir, bool recursive = false);
|
||||
|
||||
FileSizeInfo m_c_sizeInfo;
|
||||
QVector<FileInformations> m_u2_memFiles;
|
||||
|
||||
QString m_lastError;
|
||||
QAtomicInt m_aborted;
|
||||
|
||||
TarFilter *m_currentTarFilter{nullptr};
|
||||
BZip2IODevice *m_currentBzipDevice{nullptr};
|
||||
|
||||
QFuture<bool> m_future;
|
||||
bool m_success{false};
|
||||
};
|
||||
|
||||
|
||||
struct FileSizeInfo
|
||||
{
|
||||
qint64 realSize = 0;
|
||||
qint64 compressedSize = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
explicit Compress(QObject *parent = nullptr);
|
||||
|
||||
~Compress();
|
||||
|
||||
|
||||
|
||||
QVector<FileInformations> getMemFiles() const { return m_u2_memFiles; }
|
||||
|
||||
|
||||
FileSizeInfo getFileSizeInfo() const { return m_c_sizeInfo; }
|
||||
|
||||
|
||||
bool success() const;
|
||||
|
||||
|
||||
|
||||
void compress(QIODevice *out,
|
||||
const QString &sourceRootDir,
|
||||
const QVector<FileInformations> &files,
|
||||
const QVector<FileInformations> &memFiles,
|
||||
const QString &destRootDir);
|
||||
|
||||
|
||||
|
||||
void compress(QIODevice *out,
|
||||
const QString &sourceDir,
|
||||
const QString &destRootDir);
|
||||
|
||||
|
||||
void uncompress(QIODevice *in,
|
||||
const QString &outDir);
|
||||
|
||||
|
||||
void uncompress(QIODevice *in);
|
||||
|
||||
|
||||
QString lastError() const { return m_lastError; }
|
||||
|
||||
|
||||
|
||||
bool waitForFinished();
|
||||
|
||||
public Q_SLOTS:
|
||||
void abort();
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
|
||||
void uncompressInfo(qint64 totalSize, qint64 curPos, const QString &curName);
|
||||
|
||||
|
||||
void compressInfo(qint64 totalFiles, qint64 curFile, const QString &curName);
|
||||
void compressInfoEx(qint64 totalFiles, qint64 curFile, qint64 totalSize, qint64 curPos, const QString &curName, const qint64 bytesTotal);
|
||||
|
||||
|
||||
|
||||
void error(const QString &errorString);
|
||||
|
||||
|
||||
|
||||
void finished();
|
||||
private:
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
bool _compress(QIODevice *output,
|
||||
const QString &filesRootDir,
|
||||
const QVector<FileInformations> &files,
|
||||
const QVector<FileInformations> &memFiles,
|
||||
const QString &_destRootDir);
|
||||
bool _uncompressDirectory(QIODevice *input, const QString &outDir);
|
||||
bool _uncompressBuffer(QIODevice *input);
|
||||
|
||||
void reset();
|
||||
void setupFutureWatcher(const QFuture<bool> &future);
|
||||
|
||||
QVector<FileInformations> directoryFileList(const QString &dir, bool recursive = false);
|
||||
|
||||
FileSizeInfo m_c_sizeInfo;
|
||||
QVector<FileInformations> m_u2_memFiles;
|
||||
|
||||
QString m_lastError;
|
||||
QAtomicInt m_aborted;
|
||||
|
||||
TarFilter *m_currentTarFilter { nullptr };
|
||||
BZip2IODevice *m_currentBzipDevice { nullptr };
|
||||
|
||||
QFuture<bool> m_future;
|
||||
bool m_success { false };
|
||||
};
|
||||
}
|
||||
Q_DECLARE_TYPEINFO(NGL::Compress::FileInformations, Q_MOVABLE_TYPE);
|
||||
|
||||
Executable → Regular
+9
-9
@@ -5,13 +5,13 @@
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef NGLCOMPRESSION_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLCOMPRESSION_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_NGLCOMPRESSION_LIB)
|
||||
# define NGLCOMPRESSION_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define NGLCOMPRESSION_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLCOMPRESSION_EXPORT
|
||||
#else
|
||||
#if defined(MAKE_NGLCOMPRESSION_LIB)
|
||||
#define NGLCOMPRESSION_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define NGLCOMPRESSION_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+78
-83
@@ -1,8 +1,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <QtCore/QBuffer>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QIODevice>
|
||||
@@ -21,20 +19,15 @@
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class TarFilter::Private
|
||||
{
|
||||
public:
|
||||
Private(QIODevice *dev)
|
||||
: device(dev)
|
||||
, iBufSize(1024 * 1024)
|
||||
, nextChunkSize(-1)
|
||||
{}
|
||||
: device(dev)
|
||||
, iBufSize(1024 * 1024)
|
||||
, nextChunkSize(-1)
|
||||
{
|
||||
}
|
||||
|
||||
struct tar_posix_header
|
||||
{
|
||||
@@ -54,21 +47,21 @@ public:
|
||||
char devmajor[8];
|
||||
char devminor[8];
|
||||
char prefix[155];
|
||||
char unused[12];
|
||||
char unused[12];
|
||||
};
|
||||
bool fi2tph(const FileInformations &infos);
|
||||
bool addHeader(const FileInformations &infos);
|
||||
bool fi2tph(const FileInformations &infos);
|
||||
bool addHeader(const FileInformations &infos);
|
||||
|
||||
bool tph2fi(FileInformations &infos);
|
||||
bool getHeader(FileInformations &infos);
|
||||
bool tph2fi(FileInformations &infos);
|
||||
bool getHeader(FileInformations &infos);
|
||||
bool checkDevice(QIODevice *in, QIODevice *out);
|
||||
bool copyData(QIODevice *in, QIODevice *out, qint64 iSize);
|
||||
|
||||
QIODevice *device;
|
||||
QString lastError;
|
||||
QIODevice *device;
|
||||
QString lastError;
|
||||
unsigned int iBufSize;
|
||||
qint64 nextChunkSize;
|
||||
QAtomicInt aborted { 0 };
|
||||
qint64 nextChunkSize;
|
||||
QAtomicInt aborted{0};
|
||||
std::function<void(qint64)> readCallback;
|
||||
};
|
||||
|
||||
@@ -83,23 +76,23 @@ bool TarFilter::Private::fi2tph(const FileInformations &infos)
|
||||
fn = fn.mid(1);
|
||||
|
||||
long unsigned int fileSize = infos.fileType == directory ? 0 : infos.fileSize;
|
||||
long unsigned int mtime = infos.mtime != -1 ? infos.mtime : time(nullptr);
|
||||
long unsigned int mtime = infos.mtime != -1 ? infos.mtime : time(nullptr);
|
||||
tar_posix_header hdr;
|
||||
memset(&hdr, 0, sizeof(hdr));
|
||||
QByteArray fn_part1 = fn.left(sizeof(hdr.name));
|
||||
memcpy(hdr.name, fn_part1.constData(), fn_part1.size());
|
||||
sprintf(hdr.mode, "%07x", 0x0fff & infos.mode);
|
||||
sprintf(hdr.uid, "%07o", infos.uid);
|
||||
sprintf(hdr.gid, "%07o", infos.gid);
|
||||
sprintf(hdr.size, "%011lo", fileSize);
|
||||
sprintf(hdr.mtime, "%011lo", mtime);
|
||||
memset(hdr.chksum, ' ', sizeof(hdr.chksum));
|
||||
memcpy(hdr.name, fn_part1.constData(), fn_part1.size());
|
||||
sprintf(hdr.mode, "%07x", 0x0fff & infos.mode);
|
||||
sprintf(hdr.uid, "%07o", infos.uid);
|
||||
sprintf(hdr.gid, "%07o", infos.gid);
|
||||
sprintf(hdr.size, "%011lo", fileSize);
|
||||
sprintf(hdr.mtime, "%011lo", mtime);
|
||||
memset(hdr.chksum, ' ', sizeof(hdr.chksum));
|
||||
hdr.typeflag = infos.fileType;
|
||||
|
||||
memcpy(hdr.magic, "ustar ",sizeof(hdr.magic) + sizeof(hdr.version));
|
||||
|
||||
memcpy(hdr.magic, "ustar ", sizeof(hdr.magic) + sizeof(hdr.version));
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
{
|
||||
QByteArray unameBa = infos.uname.toUtf8();
|
||||
@@ -108,9 +101,7 @@ bool TarFilter::Private::fi2tph(const FileInformations &infos)
|
||||
qstrncpy(hdr.gname, gnameBa.constData(), sizeof(hdr.gname));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
unsigned int checksum = 0;
|
||||
const unsigned char *ptr = reinterpret_cast<const unsigned char *>(&hdr);
|
||||
@@ -133,7 +124,7 @@ bool TarFilter::Private::fi2tph(const FileInformations &infos)
|
||||
|
||||
bool TarFilter::Private::addHeader(const FileInformations &infos)
|
||||
{
|
||||
|
||||
|
||||
|
||||
QByteArray fn = infos.fileName.toUtf8();
|
||||
#ifdef Q_OS_WIN
|
||||
@@ -152,10 +143,10 @@ bool TarFilter::Private::addHeader(const FileInformations &infos)
|
||||
FileInformations longlink;
|
||||
longlink.fileName = QLatin1String("././@LongLink");
|
||||
longlink.fileType = gnu_longname;
|
||||
longlink.fileSize = strlen(fn.constData()) + 1;
|
||||
longlink.mtime = 0;
|
||||
longlink.uid = 0;
|
||||
longlink.gid = 0;
|
||||
longlink.fileSize = strlen(fn.constData()) + 1;
|
||||
longlink.mtime = 0;
|
||||
longlink.uid = 0;
|
||||
longlink.gid = 0;
|
||||
#ifndef Q_OS_WIN
|
||||
struct passwd *p = getpwuid(longlink.uid);
|
||||
if (p)
|
||||
@@ -195,8 +186,7 @@ bool TarFilter::Private::tph2fi(FileInformations &infos)
|
||||
lastError = QStringLiteral("Error reading from QIODevice! needed: %1, got: %2").arg(sizeof(hdr)).arg(iBytesRead);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
while (memcmp(hdr.magic, "\0\0\0\0\0\0", sizeof(hdr.magic)) == 0);
|
||||
} while (memcmp(hdr.magic, "\0\0\0\0\0\0", sizeof(hdr.magic)) == 0);
|
||||
if (memcmp(hdr.magic, "ustar ", sizeof(hdr.magic)))
|
||||
{
|
||||
lastError = QLatin1String("The archive is not supported");
|
||||
@@ -214,17 +204,17 @@ bool TarFilter::Private::tph2fi(FileInformations &infos)
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray ba(hdr.name, sizeof(hdr.name));
|
||||
QByteArray ba(hdr.name, sizeof(hdr.name));
|
||||
ba.resize(qstrlen(ba.constData()));
|
||||
infos.fileName = QString::fromUtf8(ba.constData());
|
||||
infos.fileSize = QByteArray(hdr.size, sizeof(hdr.size)).toUInt(nullptr, 8);
|
||||
infos.mode = static_cast<QFile::Permissions>(QByteArray(hdr.mode, sizeof(hdr.mode)).toUInt(nullptr, 16));
|
||||
infos.uid = QByteArray(hdr.uid, sizeof(hdr.uid)).toUInt(nullptr, 8);
|
||||
infos.gid = QByteArray(hdr.gid, sizeof(hdr.gid)).toUInt(nullptr, 8);
|
||||
infos.mtime = QByteArray(hdr.mtime, sizeof(hdr.mtime)).toUInt(nullptr, 8);
|
||||
infos.fileSize = QByteArray(hdr.size, sizeof(hdr.size)).toUInt(nullptr, 8);
|
||||
infos.mode = static_cast<QFile::Permissions>(QByteArray(hdr.mode, sizeof(hdr.mode)).toUInt(nullptr, 16));
|
||||
infos.uid = QByteArray(hdr.uid, sizeof(hdr.uid)).toUInt(nullptr, 8);
|
||||
infos.gid = QByteArray(hdr.gid, sizeof(hdr.gid)).toUInt(nullptr, 8);
|
||||
infos.mtime = QByteArray(hdr.mtime, sizeof(hdr.mtime)).toUInt(nullptr, 8);
|
||||
infos.fileType = (FileType)hdr.typeflag;
|
||||
infos.uname = QString::fromUtf8(QByteArray(hdr.uname, sizeof(hdr.uname)).constData());
|
||||
infos.gname = QString::fromUtf8(QByteArray(hdr.gname, sizeof(hdr.gname)).constData());
|
||||
infos.uname = QString::fromUtf8(QByteArray(hdr.uname, sizeof(hdr.uname)).constData());
|
||||
infos.gname = QString::fromUtf8(QByteArray(hdr.gname, sizeof(hdr.gname)).constData());
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -235,14 +225,14 @@ bool TarFilter::Private::getHeader(FileInformations &infos)
|
||||
return false;
|
||||
switch (infos.fileType)
|
||||
{
|
||||
case regular:
|
||||
case regular2:
|
||||
case directory:
|
||||
case gnu_longname:
|
||||
break;
|
||||
default:
|
||||
lastError = QStringLiteral("Unsupported fileType %1").arg(infos.fileType);
|
||||
return false;
|
||||
case regular:
|
||||
case regular2:
|
||||
case directory:
|
||||
case gnu_longname:
|
||||
break;
|
||||
default:
|
||||
lastError = QStringLiteral("Unsupported fileType %1").arg(infos.fileType);
|
||||
return false;
|
||||
}
|
||||
if (infos.fileType == gnu_longname)
|
||||
{
|
||||
@@ -254,7 +244,7 @@ bool TarFilter::Private::getHeader(FileInformations &infos)
|
||||
}
|
||||
if (!tph2fi(infos))
|
||||
return false;
|
||||
const int len = qstrlen(fn.constData());
|
||||
const int len = qstrlen(fn.constData());
|
||||
infos.fileName = QString::fromUtf8(fn.constData(), len);
|
||||
}
|
||||
|
||||
@@ -294,12 +284,14 @@ bool TarFilter::Private::copyData(QIODevice *in, QIODevice *out, qint64 iSize)
|
||||
|
||||
while (iSize > 0)
|
||||
{
|
||||
if (aborted) return false;
|
||||
if (aborted)
|
||||
return false;
|
||||
|
||||
const qint64 iBytesToRead = iSize > iBufSize ? iBufSize : iSize;
|
||||
const QByteArray ba = in->read(iBytesToRead);
|
||||
|
||||
if (aborted) return false;
|
||||
if (aborted)
|
||||
return false;
|
||||
|
||||
if (ba.size() == 0)
|
||||
{
|
||||
@@ -321,10 +313,8 @@ bool TarFilter::Private::copyData(QIODevice *in, QIODevice *out, qint64 iSize)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TarFilter::TarFilter(QIODevice *dev, const std::function<void(qint64)> &readCallback)
|
||||
: d(new Private(dev))
|
||||
: d(new Private(dev))
|
||||
{
|
||||
d->readCallback = readCallback;
|
||||
}
|
||||
@@ -371,17 +361,17 @@ bool TarFilter::addFile(const QString &filename, const QString &filenameInArchiv
|
||||
FileInformations fInfos;
|
||||
fInfos.fileName = (filenameInArchive.isEmpty() ? filename : filenameInArchive);
|
||||
fInfos.fileSize = fi.isDir() ? 0 : fi.size();
|
||||
fInfos.mode = fi.permissions() & 0x0fff;
|
||||
fInfos.mode = fi.permissions() & 0x0fff;
|
||||
#ifdef Q_OS_WIN
|
||||
fInfos.uid = 1000;
|
||||
fInfos.gid = 100;
|
||||
fInfos.uid = 1000;
|
||||
fInfos.gid = 100;
|
||||
#else
|
||||
fInfos.uid = fi.ownerId();
|
||||
fInfos.gid = fi.groupId();
|
||||
fInfos.uname = fi.owner();
|
||||
fInfos.gname = fi.group();
|
||||
fInfos.uid = fi.ownerId();
|
||||
fInfos.gid = fi.groupId();
|
||||
fInfos.uname = fi.owner();
|
||||
fInfos.gname = fi.group();
|
||||
#endif
|
||||
fInfos.mtime = fi.lastModified().toSecsSinceEpoch();
|
||||
fInfos.mtime = fi.lastModified().toSecsSinceEpoch();
|
||||
fInfos.fileType = fi.isDir() ? directory : regular;
|
||||
|
||||
if (fi.isDir())
|
||||
@@ -397,23 +387,25 @@ bool TarFilter::addFile(const QString &filename, const QString &filenameInArchiv
|
||||
return false;
|
||||
}
|
||||
|
||||
if (d->aborted) return false;
|
||||
if (d->aborted)
|
||||
return false;
|
||||
|
||||
return addData(fInfos, &f);
|
||||
}
|
||||
|
||||
bool TarFilter::addData(const QString &filename, const QByteArray &data, bool bIsDir)
|
||||
{
|
||||
if (d->aborted) return false;
|
||||
if (d->aborted)
|
||||
return false;
|
||||
|
||||
FileInformations fi;
|
||||
fi.fileName = filename;
|
||||
fi.fileSize = bIsDir ? 0 : data.size();
|
||||
fi.mode = static_cast<QFile::Permissions>(bIsDir ? 0x0755 : 0x0644);
|
||||
fi.fileSize = bIsDir ? 0 : data.size();
|
||||
fi.mode = static_cast<QFile::Permissions>(bIsDir ? 0x0755 : 0x0644);
|
||||
fi.fileType = bIsDir ? directory : regular;
|
||||
#ifndef Q_OS_WIN
|
||||
fi.uid = getuid();
|
||||
fi.gid = getgid();
|
||||
fi.uid = getuid();
|
||||
fi.gid = getgid();
|
||||
char name[256];
|
||||
struct passwd *p_ptr = nullptr;
|
||||
struct passwd p;
|
||||
@@ -438,7 +430,8 @@ bool TarFilter::addData(const QString &filename, const QByteArray &data, bool bI
|
||||
|
||||
bool TarFilter::addData(const FileInformations &fi, QIODevice *in)
|
||||
{
|
||||
if (d->aborted) return false;
|
||||
if (d->aborted)
|
||||
return false;
|
||||
|
||||
if (!d->checkDevice(in, d->device))
|
||||
return false;
|
||||
@@ -464,7 +457,7 @@ bool TarFilter::addData(const FileInformations &fi, QIODevice *in)
|
||||
|
||||
bool TarFilter::writeEOS()
|
||||
{
|
||||
|
||||
|
||||
const int size = sizeof(TarFilter::Private::tar_posix_header) * 2;
|
||||
QByteArray ba(size, '\0');
|
||||
return (d->device->write(ba) == size);
|
||||
@@ -472,7 +465,8 @@ bool TarFilter::writeEOS()
|
||||
|
||||
bool TarFilter::getData(FileInformations &fi)
|
||||
{
|
||||
if (d->aborted) return false;
|
||||
if (d->aborted)
|
||||
return false;
|
||||
|
||||
d->nextChunkSize = -1;
|
||||
if (!d->getHeader(fi))
|
||||
@@ -483,7 +477,8 @@ bool TarFilter::getData(FileInformations &fi)
|
||||
|
||||
bool TarFilter::getData(QIODevice *out)
|
||||
{
|
||||
if (d->aborted) return false;
|
||||
if (d->aborted)
|
||||
return false;
|
||||
|
||||
if (!d->checkDevice(d->device, out))
|
||||
return false;
|
||||
|
||||
Executable → Regular
+28
-32
@@ -1,8 +1,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef TARFILTER_H
|
||||
#define TARFILTER_H
|
||||
|
||||
@@ -14,7 +12,6 @@ class QIODevice;
|
||||
class QByteArray;
|
||||
|
||||
|
||||
|
||||
class TarFilter
|
||||
{
|
||||
public:
|
||||
@@ -22,53 +19,52 @@ public:
|
||||
|
||||
enum FileType
|
||||
{
|
||||
regular = '0',
|
||||
regular2 = '\0',
|
||||
link = '1',
|
||||
reserved = '2',
|
||||
charType = '3',
|
||||
block = '4',
|
||||
regular = '0',
|
||||
regular2 = '\0',
|
||||
link = '1',
|
||||
reserved = '2',
|
||||
charType = '3',
|
||||
block = '4',
|
||||
directory = '5',
|
||||
fifo = '6',
|
||||
fifo = '6',
|
||||
reserved2 = '7',
|
||||
gnu_longLink = 'K',
|
||||
gnu_longname = 'L',
|
||||
gnu_longLink = 'K',
|
||||
gnu_longname = 'L',
|
||||
};
|
||||
struct FileInformations
|
||||
{
|
||||
QString fileName;
|
||||
qint64 fileSize = 0;
|
||||
int uid = 1000;
|
||||
int gid = 100;
|
||||
QString uname;
|
||||
QString gname;
|
||||
time_t mtime = -1;
|
||||
FileType fileType = regular;
|
||||
QString fileName;
|
||||
qint64 fileSize = 0;
|
||||
int uid = 1000;
|
||||
int gid = 100;
|
||||
QString uname;
|
||||
QString gname;
|
||||
time_t mtime = -1;
|
||||
FileType fileType = regular;
|
||||
QFile::Permissions mode = QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
TarFilter(QIODevice *dev, const std::function<void(qint64)> &readCallback = nullptr);
|
||||
~TarFilter();
|
||||
|
||||
void abort();
|
||||
void setBufferSize(unsigned int size);
|
||||
bool error() const;
|
||||
QString lastError() const;
|
||||
void setBufferSize(unsigned int size);
|
||||
bool error() const;
|
||||
QString lastError() const;
|
||||
|
||||
|
||||
|
||||
bool addData(const FileInformations &fi, QIODevice *in);
|
||||
|
||||
|
||||
bool addFile(const QString &filename, const QString &filenameInArchive = QString());
|
||||
bool addData(const QString &filename, const QByteArray &data = QByteArray(), bool bIsDir = false);
|
||||
|
||||
|
||||
bool writeEOS();
|
||||
|
||||
|
||||
|
||||
bool getData(FileInformations &fi, QIODevice *out);
|
||||
|
||||
bool getData(FileInformations &fi);
|
||||
|
||||
bool getData(FileInformations &fi);
|
||||
bool getData(QIODevice *out);
|
||||
bool getData(FileInformations &fi, QByteArray &data);
|
||||
|
||||
@@ -77,4 +73,4 @@ private:
|
||||
Private *const d;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+5
-37
@@ -12,7 +12,6 @@
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
|
||||
void nglcomp_test::initTestCase()
|
||||
{
|
||||
m_tempDirIn.setAutoRemove(true);
|
||||
@@ -22,23 +21,18 @@ void nglcomp_test::initTestCase()
|
||||
QVERIFY(m_tf.open());
|
||||
m_tf.setAutoRemove(true);
|
||||
|
||||
m_fileContent[QLatin1String("1.txt")] = "111111111111111111111111";
|
||||
m_fileContent[QLatin1String("sub1/s1.txt")] = "222222222222222222222222";
|
||||
m_fileContent[QLatin1String("1.txt")] = "111111111111111111111111";
|
||||
m_fileContent[QLatin1String("sub1/s1.txt")] = "222222222222222222222222";
|
||||
m_fileContent[QLatin1String("sub1/sub11/s11.txt")] = "333333333333333333333333";
|
||||
m_fileContent[QLatin1String("sub1/sub12/s12.txt")] = "444444444444444444444444";
|
||||
m_fileContent[QLatin1String("sub2/2.txt")] = "555555555555555555555555";
|
||||
m_fileContent[QLatin1String("sub2/2.txt")] = "555555555555555555555555";
|
||||
}
|
||||
|
||||
|
||||
void nglcomp_test::testCompressFile()
|
||||
{
|
||||
QDir dir;
|
||||
const auto directories = {
|
||||
QLatin1String("sub1"),
|
||||
QLatin1String("sub1/sub11"),
|
||||
QLatin1String("sub1/sub12"),
|
||||
QLatin1String("sub2")
|
||||
};
|
||||
const auto directories = {QLatin1String("sub1"), QLatin1String("sub1/sub11"), QLatin1String("sub1/sub12"), QLatin1String("sub2")};
|
||||
for (const QLatin1String &directory : directories)
|
||||
QVERIFY(dir.mkdir(subPathIn(directory)));
|
||||
|
||||
@@ -113,7 +107,6 @@ void nglcomp_test::cleanupTestCase()
|
||||
}
|
||||
|
||||
|
||||
|
||||
void nglcomp_test::writeTestFile(const QString &fn, const QByteArray &content) const
|
||||
{
|
||||
QFile f(subPathIn(fn));
|
||||
@@ -140,35 +133,10 @@ QString nglcomp_test::subPathOut(const QString &p) const
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
|
||||
|
||||
app.createLogger("nglcomp_test", "log4cxx_nglcomp_test.props");
|
||||
nglcomp_test tc;
|
||||
return QTest::qExec(&tc, argc, argv);
|
||||
|
||||
Executable → Regular
+2
@@ -22,11 +22,13 @@ private Q_SLOTS:
|
||||
void testUncompressFile();
|
||||
void testUncompressMemory();
|
||||
void cleanupTestCase();
|
||||
|
||||
private:
|
||||
void writeTestFile(const QString &fn, const QByteArray &content) const;
|
||||
void checkContent(const QString &fn, const QByteArray &content) const;
|
||||
QString subPathIn(const QString &p) const;
|
||||
QString subPathOut(const QString &p) const;
|
||||
|
||||
private:
|
||||
QHash<QString, QByteArray> m_fileContent;
|
||||
QByteArray m_ba;
|
||||
|
||||
Executable → Regular
+38
-39
@@ -8,51 +8,50 @@
|
||||
class QSqlDatabase;
|
||||
namespace NGLDB
|
||||
{
|
||||
template<typename DB>
|
||||
class DbServiceHandler
|
||||
{
|
||||
public:
|
||||
DbServiceHandler() = default;
|
||||
~DbServiceHandler() = default;
|
||||
|
||||
|
||||
bool init(int exerciseId, NGL::Settings *settings)
|
||||
template <typename DB> class DbServiceHandler
|
||||
{
|
||||
if (m_dbInterface)
|
||||
return true;
|
||||
public:
|
||||
DbServiceHandler() = default;
|
||||
~DbServiceHandler() = default;
|
||||
|
||||
m_dbInterface = DB::create(exerciseId);
|
||||
|
||||
if (!m_dbInterface->init(m_dbInterface->dbUser(),
|
||||
settings->databasePassword(m_dbInterface->dbUser()),
|
||||
settings->databaseDriver(),
|
||||
settings->databaseHostname(),
|
||||
settings->databaseName()))
|
||||
bool init(int exerciseId, NGL::Settings *settings)
|
||||
{
|
||||
m_dbInterface = nullptr;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (m_dbInterface)
|
||||
return true;
|
||||
|
||||
bool init(int exerciseId, const QSqlDatabase &db)
|
||||
{
|
||||
if (m_dbInterface)
|
||||
m_dbInterface = DB::create(exerciseId);
|
||||
|
||||
if (!m_dbInterface->init(m_dbInterface->dbUser(),
|
||||
settings->databasePassword(m_dbInterface->dbUser()),
|
||||
settings->databaseDriver(),
|
||||
settings->databaseHostname(),
|
||||
settings->databaseName()))
|
||||
{
|
||||
m_dbInterface = nullptr;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
m_dbInterface = DB::create(exerciseId);
|
||||
|
||||
if (!m_dbInterface->init(db))
|
||||
{
|
||||
m_dbInterface = nullptr;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<DB> db() const { return m_dbInterface; }
|
||||
bool init(int exerciseId, const QSqlDatabase &db)
|
||||
{
|
||||
if (m_dbInterface)
|
||||
return true;
|
||||
|
||||
private:
|
||||
std::shared_ptr<DB> m_dbInterface;
|
||||
};
|
||||
}
|
||||
m_dbInterface = DB::create(exerciseId);
|
||||
|
||||
if (!m_dbInterface->init(db))
|
||||
{
|
||||
m_dbInterface = nullptr;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<DB> db() const { return m_dbInterface; }
|
||||
|
||||
private:
|
||||
std::shared_ptr<DB> m_dbInterface;
|
||||
};
|
||||
}
|
||||
Executable → Regular
+18
-22
@@ -7,35 +7,31 @@
|
||||
#include <QtCore/QString>
|
||||
|
||||
|
||||
|
||||
namespace DBCommon
|
||||
{
|
||||
|
||||
enum class eDatabaseSchema
|
||||
{
|
||||
Exercise
|
||||
};
|
||||
enum class eDatabaseSchema
|
||||
{
|
||||
Exercise
|
||||
};
|
||||
|
||||
|
||||
inline QString getExerciseSchemaName(int exerciseId)
|
||||
{
|
||||
return QLatin1String("ex_") + QString::number(exerciseId);
|
||||
}
|
||||
|
||||
inline QString getExerciseSchemaName(int exerciseId)
|
||||
{
|
||||
return QLatin1String("ex_") + QString::number(exerciseId);
|
||||
}
|
||||
|
||||
inline QString getTableName(const QString &tableName, const QString &schemaName)
|
||||
{
|
||||
if (schemaName.isEmpty())
|
||||
return tableName;
|
||||
return schemaName + QLatin1Char('.') + tableName;
|
||||
}
|
||||
|
||||
|
||||
inline QString getTableName(const QString &tableName, const QString &schemaName)
|
||||
{
|
||||
if (schemaName.isEmpty())
|
||||
return tableName;
|
||||
return schemaName + QLatin1Char('.') + tableName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline QString getExerciseTableName(const QString &tableName, int exerciseId)
|
||||
{
|
||||
return getTableName(tableName, getExerciseSchemaName(exerciseId));
|
||||
}
|
||||
inline QString getExerciseTableName(const QString &tableName, int exerciseId)
|
||||
{
|
||||
return getTableName(tableName, getExerciseSchemaName(exerciseId));
|
||||
}
|
||||
}
|
||||
Executable → Regular
+44
-47
@@ -11,58 +11,55 @@
|
||||
namespace DBConnection
|
||||
{
|
||||
|
||||
QSqlDatabase open(NGL::INGLLogger &logger,
|
||||
const QString &dbUser,
|
||||
const QString &dbPasswd,
|
||||
const QString &dbDriver,
|
||||
const QString &dbHost,
|
||||
const QString &dbName,
|
||||
const QString &schemaName,
|
||||
const QString &connectionName)
|
||||
{
|
||||
|
||||
|
||||
|
||||
DEBUG_LOG(logger) << "host: " << dbHost << " database: " << dbName;
|
||||
QString realConnectionName(connectionName);
|
||||
if (connectionName.isEmpty())
|
||||
QSqlDatabase open(NGL::INGLLogger &logger,
|
||||
const QString &dbUser,
|
||||
const QString &dbPasswd,
|
||||
const QString &dbDriver,
|
||||
const QString &dbHost,
|
||||
const QString &dbName,
|
||||
const QString &schemaName,
|
||||
const QString &connectionName)
|
||||
{
|
||||
realConnectionName = dbHost + QLatin1Char('_') + dbName;
|
||||
|
||||
|
||||
DEBUG_LOG(logger) << "host: " << dbHost << " database: " << dbName;
|
||||
QString realConnectionName(connectionName);
|
||||
if (connectionName.isEmpty())
|
||||
{
|
||||
realConnectionName = dbHost + QLatin1Char('_') + dbName;
|
||||
if (!schemaName.isEmpty())
|
||||
realConnectionName += QLatin1Char('_') + schemaName;
|
||||
}
|
||||
|
||||
auto dbConnection = QSqlDatabase::addDatabase(dbDriver, realConnectionName);
|
||||
dbConnection.setHostName(dbHost);
|
||||
dbConnection.setDatabaseName(dbName);
|
||||
dbConnection.setUserName(dbUser);
|
||||
dbConnection.setPassword(dbPasswd);
|
||||
|
||||
if (!dbConnection.open())
|
||||
{
|
||||
const QString err = dbConnection.lastError().nativeErrorCode();
|
||||
FATAL_LOG(logger) << "Error opening database " << dbHost << ":" << dbName << " as user " << dbUser;
|
||||
FATAL_LOG(logger) << dbConnection.lastError().driverText() << " " << dbConnection.lastError().databaseText() << " " << err;
|
||||
return dbConnection;
|
||||
}
|
||||
|
||||
DEBUG_LOG(logger) << "Database Initialisation successful -> DB: " << dbName << ", con: " << realConnectionName;
|
||||
|
||||
if (!schemaName.isEmpty())
|
||||
realConnectionName += QLatin1Char('_') + schemaName;
|
||||
}
|
||||
{
|
||||
const QString stmt = QLatin1String("SET SEARCH_PATH TO ") + schemaName + QLatin1String(", PUBLIC");
|
||||
|
||||
auto dbConnection = QSqlDatabase::addDatabase(dbDriver, realConnectionName);
|
||||
dbConnection.setHostName(dbHost);
|
||||
dbConnection.setDatabaseName(dbName);
|
||||
dbConnection.setUserName(dbUser);
|
||||
dbConnection.setPassword(dbPasswd);
|
||||
NSqlQuery q(dbConnection);
|
||||
if (!q.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(logger) << "Set SEARCH_PATH to " << schemaName << " failed!";
|
||||
dbConnection.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (!dbConnection.open())
|
||||
{
|
||||
const QString err = dbConnection.lastError().nativeErrorCode();
|
||||
FATAL_LOG(logger) << "Error opening database " << dbHost
|
||||
<< ":" << dbName << " as user " << dbUser;
|
||||
FATAL_LOG(logger) << dbConnection.lastError().driverText() << " "
|
||||
<< dbConnection.lastError().databaseText() << " " << err;
|
||||
return dbConnection;
|
||||
}
|
||||
|
||||
DEBUG_LOG(logger) << "Database Initialisation successful -> DB: " << dbName << ", con: " << realConnectionName;
|
||||
|
||||
if (!schemaName.isEmpty())
|
||||
{
|
||||
const QString stmt = QLatin1String("SET SEARCH_PATH TO ") + schemaName + QLatin1String(", PUBLIC");
|
||||
|
||||
NSqlQuery q(dbConnection);
|
||||
if (!q.exec(stmt))
|
||||
{
|
||||
ERROR_LOG(logger) << "Set SEARCH_PATH to " << schemaName << " failed!";
|
||||
dbConnection.close();
|
||||
}
|
||||
}
|
||||
|
||||
return dbConnection;
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+10
-10
@@ -8,17 +8,17 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
namespace DBConnection
|
||||
{
|
||||
NGLDB_EXPORT QSqlDatabase open(NGL::INGLLogger &logger,
|
||||
const QString &dbUser,
|
||||
const QString &dbPasswd,
|
||||
const QString &dbDriver,
|
||||
const QString &dbHost,
|
||||
const QString &dbName,
|
||||
const QString &schemaName = QString(),
|
||||
const QString &connectionName = QString());
|
||||
}
|
||||
NGLDB_EXPORT QSqlDatabase open(NGL::INGLLogger &logger,
|
||||
const QString &dbUser,
|
||||
const QString &dbPasswd,
|
||||
const QString &dbDriver,
|
||||
const QString &dbHost,
|
||||
const QString &dbName,
|
||||
const QString &schemaName = QString(),
|
||||
const QString &connectionName = QString());
|
||||
}
|
||||
Executable → Regular
+3
-3
@@ -8,9 +8,9 @@
|
||||
thread_local int s_refCounter = 0;
|
||||
|
||||
DBTransaction::DBTransaction(const QSqlDatabase &db)
|
||||
: m_db(db)
|
||||
, m_bCommitted(true)
|
||||
, mLogger(NGLDB::getLogger("DBTransaction"))
|
||||
: m_db(db)
|
||||
, m_bCommitted(true)
|
||||
, mLogger(NGLDB::getLogger("DBTransaction"))
|
||||
{
|
||||
++s_refCounter;
|
||||
if (s_refCounter == 1)
|
||||
|
||||
Executable → Regular
+4
-10
@@ -8,31 +8,27 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
|
||||
class NGLDB_EXPORT DBTransaction
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
explicit DBTransaction(const QSqlDatabase &db);
|
||||
|
||||
|
||||
|
||||
~DBTransaction();
|
||||
|
||||
|
||||
|
||||
bool begin();
|
||||
|
||||
|
||||
|
||||
bool commit();
|
||||
|
||||
|
||||
|
||||
bool rollback();
|
||||
|
||||
|
||||
|
||||
bool state() const;
|
||||
|
||||
@@ -44,5 +40,3 @@ private:
|
||||
bool m_lastState;
|
||||
NGL::INGLLogger &mLogger;
|
||||
};
|
||||
|
||||
|
||||
Executable → Regular
+9
-9
@@ -5,13 +5,13 @@
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef NGLDB_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLDB_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_NGLDB_LIB)
|
||||
# define NGLDB_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define NGLDB_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLDB_EXPORT
|
||||
#else
|
||||
#if defined(MAKE_NGLDB_LIB)
|
||||
#define NGLDB_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define NGLDB_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+5
-4
@@ -13,10 +13,11 @@ NGLDB::LOGGER_T NGLDB::getLogger(const char *name)
|
||||
loggerName.append(ns, sizeof(ns) - 1);
|
||||
loggerName.append(name, len);
|
||||
|
||||
try {
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
|
||||
getNGLLogger( loggerName );
|
||||
} catch ( const std::exception &ex )
|
||||
try
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(loggerName);
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
||||
abort();
|
||||
|
||||
Executable → Regular
+8
-8
@@ -12,8 +12,8 @@
|
||||
#endif
|
||||
|
||||
#ifdef NGLDB_ENABLE_TRACE
|
||||
#define DB_TRACE { TRACE_LOG(mLogger) << DB_TRACE_FUNCTION }
|
||||
#define DB_TRACE2(x) { TRACE_LOG(mLogger) << DB_TRACE_FUNCTION << x }
|
||||
#define DB_TRACE {TRACE_LOG(mLogger) << DB_TRACE_FUNCTION}
|
||||
#define DB_TRACE2(x) {TRACE_LOG(mLogger) << DB_TRACE_FUNCTION << x}
|
||||
#else
|
||||
#define DB_TRACE
|
||||
#define DB_TRACE2(x)
|
||||
@@ -21,11 +21,11 @@
|
||||
|
||||
namespace NGLDB
|
||||
{
|
||||
typedef NGL::INGLLogger &LOGGER_T;
|
||||
typedef NGL::INGLLogger &LOGGER_T;
|
||||
|
||||
LOGGER_T getLogger(const char *name);
|
||||
inline LOGGER_T getLogger(const QString &loggerName)
|
||||
{
|
||||
return getLogger(loggerName.toUtf8().constData());
|
||||
LOGGER_T getLogger(const char *name);
|
||||
inline LOGGER_T getLogger(const QString &loggerName)
|
||||
{
|
||||
return getLogger(loggerName.toUtf8().constData());
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable → Regular
+20
-22
@@ -20,42 +20,40 @@
|
||||
|
||||
static QString getSqlErrorString(const QSqlError &error)
|
||||
{
|
||||
return error.driverText() + QLatin1Char(' ') +
|
||||
error.databaseText() + QLatin1Char(' ') +
|
||||
error.nativeErrorCode();
|
||||
return error.driverText() + QLatin1Char(' ') + error.databaseText() + QLatin1Char(' ') + error.nativeErrorCode();
|
||||
}
|
||||
|
||||
NSqlQuery::NSqlQuery(const QSqlDatabase &db)
|
||||
: QSqlQuery(db)
|
||||
, m_db(db)
|
||||
, mLogger(NGLDB::getLogger("NSqlQuery"))
|
||||
: QSqlQuery(db)
|
||||
, m_db(db)
|
||||
, mLogger(NGLDB::getLogger("NSqlQuery"))
|
||||
{
|
||||
DB_TRACE
|
||||
setForwardOnly(true);
|
||||
}
|
||||
|
||||
NSqlQuery::NSqlQuery(const QSqlDatabase &db, NGL::INGLLogger &logger)
|
||||
: QSqlQuery(db)
|
||||
, m_db(db)
|
||||
, mLogger(logger)
|
||||
: QSqlQuery(db)
|
||||
, m_db(db)
|
||||
, mLogger(logger)
|
||||
{
|
||||
DB_TRACE
|
||||
setForwardOnly(true);
|
||||
}
|
||||
|
||||
NSqlQuery::NSqlQuery(const QString &query, const QSqlDatabase &db)
|
||||
: QSqlQuery(query, db)
|
||||
, m_db(db)
|
||||
, mLogger(NGLDB::getLogger("NSqlQuery"))
|
||||
: QSqlQuery(query, db)
|
||||
, m_db(db)
|
||||
, mLogger(NGLDB::getLogger("NSqlQuery"))
|
||||
{
|
||||
DB_TRACE
|
||||
setForwardOnly(true);
|
||||
}
|
||||
|
||||
NSqlQuery::NSqlQuery(const QString &query, const QSqlDatabase &db, NGL::INGLLogger &logger)
|
||||
: QSqlQuery(query, db)
|
||||
, m_db(db)
|
||||
, mLogger(logger)
|
||||
: QSqlQuery(query, db)
|
||||
, m_db(db)
|
||||
, mLogger(logger)
|
||||
{
|
||||
DB_TRACE
|
||||
setForwardOnly(true);
|
||||
@@ -143,12 +141,12 @@ bool NSqlQuery::exec(bool bEmitMessageOnError)
|
||||
if (mLogger.isDebugEnabled())
|
||||
{
|
||||
const QMap<QString, QVariant> &boundValuesMap = boundValues();
|
||||
for (auto it=boundValuesMap.begin(); it != boundValuesMap.end(); ++it)
|
||||
for (auto it = boundValuesMap.begin(); it != boundValuesMap.end(); ++it)
|
||||
{
|
||||
if ( it.value().canConvert<QString>())
|
||||
DEBUG_LOG(mLogger) << "key='" << it.key() << "' value='" << it.value().toString() << "'";
|
||||
if (it.value().canConvert<QString>())
|
||||
DEBUG_LOG(mLogger) << "key='" << it.key() << "' value='" << it.value().toString() << "'";
|
||||
else
|
||||
DEBUG_LOG(mLogger) << "key='" << it.key() << "' value cant Convert to string'";
|
||||
DEBUG_LOG(mLogger) << "key='" << it.key() << "' value cant Convert to string'";
|
||||
}
|
||||
}
|
||||
if (QSqlQuery::exec())
|
||||
@@ -257,7 +255,7 @@ QString NSqlQuery::sqlstate()
|
||||
#ifdef PostgreSQL_FOUND
|
||||
if (resultHandle.isValid() && (qstrcmp(resultHandle.typeName(), "PGresult*") == 0))
|
||||
{
|
||||
const PGresult *pgresHandle = *static_cast<const PGresult * const *>(resultHandle.data());
|
||||
const PGresult *pgresHandle = *static_cast<const PGresult *const *>(resultHandle.data());
|
||||
|
||||
if (pgresHandle != nullptr)
|
||||
{
|
||||
@@ -265,7 +263,7 @@ QString NSqlQuery::sqlstate()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return QStringLiteral("58000");
|
||||
}
|
||||
|
||||
@@ -383,7 +381,7 @@ QVariant NSqlQuery::value(int index) const
|
||||
return QSqlQuery::value(index);
|
||||
}
|
||||
|
||||
NSqlQuery &NSqlQuery::operator= (const NSqlQuery &other)
|
||||
NSqlQuery &NSqlQuery::operator=(const NSqlQuery &other)
|
||||
{
|
||||
DB_TRACE
|
||||
// Use move assignment to avoid deprecated copy-assignment of QSqlQuery.
|
||||
|
||||
Executable → Regular
+6
-51
@@ -10,205 +10,160 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
class QDateTime;
|
||||
class QJsonValue;
|
||||
|
||||
|
||||
|
||||
class NGLDB_EXPORT NSqlQuery final : public QSqlQuery
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
explicit NSqlQuery(const QSqlDatabase &db);
|
||||
explicit NSqlQuery(const QSqlDatabase &db, NGL::INGLLogger &logger);
|
||||
explicit NSqlQuery(const QString &query, const QSqlDatabase &db);
|
||||
explicit NSqlQuery(const QString &query, const QSqlDatabase &db, NGL::INGLLogger &logger);
|
||||
|
||||
|
||||
|
||||
NSqlQuery(const NSqlQuery &other) = default;
|
||||
|
||||
|
||||
|
||||
~NSqlQuery() = default;
|
||||
|
||||
|
||||
|
||||
void addBindValue(const QVariant &val, QSql::ParamType paramType = QSql::In);
|
||||
|
||||
|
||||
|
||||
int at() const;
|
||||
|
||||
|
||||
|
||||
void bindValue(const QString &placeholder, const QVariant &val, QSql::ParamType paramType = QSql::In);
|
||||
|
||||
|
||||
|
||||
void bindValue(int pos, const QVariant &val, QSql::ParamType paramType = QSql::In);
|
||||
|
||||
|
||||
|
||||
QVariant boundValue(const QString &placeholder) const;
|
||||
|
||||
|
||||
|
||||
QVariant boundValue(int pos) const;
|
||||
|
||||
|
||||
|
||||
QMap<QString, QVariant> boundValues() const;
|
||||
|
||||
|
||||
|
||||
void clear();
|
||||
|
||||
|
||||
|
||||
const QSqlDriver *driver() const;
|
||||
|
||||
|
||||
|
||||
bool exec(const QString &query, bool bEmitMessageOnError = true);
|
||||
|
||||
|
||||
|
||||
bool exec(bool bEmitMessageOnError = true);
|
||||
|
||||
|
||||
|
||||
bool execAndFetch();
|
||||
|
||||
|
||||
|
||||
bool execAndFetch(const QString &query);
|
||||
|
||||
|
||||
|
||||
bool execBatch(BatchExecutionMode mode = ValuesAsRows);
|
||||
|
||||
|
||||
|
||||
QString executedQuery() const;
|
||||
|
||||
|
||||
|
||||
void finish();
|
||||
|
||||
|
||||
|
||||
bool first();
|
||||
|
||||
|
||||
|
||||
bool isActive() const;
|
||||
|
||||
|
||||
|
||||
bool isForwardOnly() const;
|
||||
|
||||
|
||||
|
||||
bool isNull(int field) const;
|
||||
|
||||
|
||||
|
||||
bool isSelect() const;
|
||||
|
||||
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
|
||||
|
||||
bool last();
|
||||
|
||||
|
||||
|
||||
QSqlError lastError() const;
|
||||
|
||||
QString sqlstate();
|
||||
|
||||
|
||||
|
||||
QVariant lastInsertId();
|
||||
|
||||
|
||||
|
||||
QString lastQuery() const;
|
||||
|
||||
|
||||
|
||||
bool next();
|
||||
|
||||
|
||||
|
||||
bool nextResult();
|
||||
|
||||
|
||||
|
||||
int numRowsAffected() const;
|
||||
|
||||
|
||||
|
||||
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
|
||||
|
||||
|
||||
|
||||
bool prepare(const QString &query);
|
||||
|
||||
|
||||
|
||||
bool previous();
|
||||
|
||||
|
||||
|
||||
QSqlRecord record() const;
|
||||
|
||||
|
||||
|
||||
const QSqlResult *result() const;
|
||||
|
||||
|
||||
|
||||
bool seek(int index, bool relative = false);
|
||||
|
||||
|
||||
|
||||
void setForwardOnly(bool forward);
|
||||
|
||||
|
||||
|
||||
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
|
||||
|
||||
|
||||
|
||||
int size() const;
|
||||
|
||||
|
||||
|
||||
QVariant value(int index) const;
|
||||
|
||||
|
||||
|
||||
NSqlQuery &operator= (const NSqlQuery &other);
|
||||
NSqlQuery &operator=(const NSqlQuery &other);
|
||||
|
||||
bool export2CSV(const QString &filename);
|
||||
|
||||
|
||||
|
||||
static QVariant qDateTimeToQVariant(const QDateTime &dt);
|
||||
|
||||
|
||||
|
||||
static QDateTime qVariantToQDateTime(const QVariant &var);
|
||||
|
||||
|
||||
|
||||
static QString qVariantToJsonString(const QVariant &value);
|
||||
|
||||
|
||||
|
||||
static QString jsonValueToJsonString(const QJsonValue &value);
|
||||
|
||||
static inline QString fixupEmptyJsonString(const QString &str) { return str.isEmpty() ? QLatin1String("{}") : str; }
|
||||
|
||||
Executable → Regular
+2
-2
@@ -7,14 +7,14 @@
|
||||
|
||||
|
||||
SqlQueryJanitor::SqlQueryJanitor(NSqlQuery *query)
|
||||
: m_query(query)
|
||||
: m_query(query)
|
||||
{
|
||||
Q_ASSERT(m_query);
|
||||
Q_ASSERT(!m_query->isActive());
|
||||
}
|
||||
|
||||
SqlQueryJanitor::SqlQueryJanitor(const std::unique_ptr<NSqlQuery> &query)
|
||||
: SqlQueryJanitor(query.get())
|
||||
: SqlQueryJanitor(query.get())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+1
-2
@@ -9,7 +9,6 @@
|
||||
class NSqlQuery;
|
||||
|
||||
|
||||
|
||||
class NGLDB_EXPORT SqlQueryJanitor
|
||||
{
|
||||
public:
|
||||
@@ -18,5 +17,5 @@ public:
|
||||
~SqlQueryJanitor();
|
||||
|
||||
private:
|
||||
NSqlQuery *m_query;
|
||||
NSqlQuery *m_query;
|
||||
};
|
||||
Executable → Regular
+154
-154
@@ -12,164 +12,164 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
namespace Connections
|
||||
{
|
||||
enum class eHostConfig
|
||||
{
|
||||
public_local,
|
||||
localhost,
|
||||
server,
|
||||
server_avs
|
||||
};
|
||||
struct configStruct
|
||||
{
|
||||
eHostConfig host;
|
||||
unsigned short port;
|
||||
QString name;
|
||||
};
|
||||
|
||||
static QMap<eConnection, configStruct> *s_config = nullptr;
|
||||
static QSettings *s_settings = nullptr;
|
||||
static unsigned short s_portOffset = 9000;
|
||||
static QString *s_serverHostname = nullptr;
|
||||
|
||||
static void cleanupSettings()
|
||||
{
|
||||
delete s_settings;
|
||||
s_settings = nullptr;
|
||||
delete s_serverHostname;
|
||||
s_serverHostname = nullptr;
|
||||
delete s_config;
|
||||
s_config = nullptr;
|
||||
}
|
||||
|
||||
static void insertConfig(eConnection conn, eHostConfig host, unsigned short port, const char *name)
|
||||
{
|
||||
if (!s_config)
|
||||
s_config = new QMap<eConnection, configStruct>();
|
||||
configStruct s;
|
||||
s.host = host;
|
||||
s.port = port;
|
||||
s.name = QString::fromLatin1(name);
|
||||
s_config->insert(conn, s);
|
||||
}
|
||||
|
||||
static void initConfig()
|
||||
{
|
||||
if (s_config && !s_config->isEmpty())
|
||||
return;
|
||||
|
||||
insertConfig(eConnection::AVS_WORKSTATION, eHostConfig::localhost, 6370, "AVS_WORKSTATION");
|
||||
insertConfig(eConnection::AVS_WORKSTATION_VD, eHostConfig::localhost, 6380, "AVS_WORKSTATION_VD");
|
||||
insertConfig(eConnection::AVS_ROOT, eHostConfig::server_avs, 6350, "AVS_ROOT");
|
||||
insertConfig(eConnection::AVS_FM, eHostConfig::server_avs, 6360, "AVS_FM");
|
||||
insertConfig(eConnection::AVS_MOTION_RECORDER, eHostConfig::server_avs, 6390, "AVS_MOTION_RECORDER");
|
||||
insertConfig(eConnection::AVS_AVA, eHostConfig::server_avs, 6391, "AVS_AVA");
|
||||
|
||||
insertConfig(eConnection::PWS_WEBSOCKET, eHostConfig::server, 5701, "PWS_WEBSOCKET");
|
||||
insertConfig(eConnection::SCM_WEBSOCKET, eHostConfig::server, 7300, "SCM_WEBSOCKET");
|
||||
insertConfig(eConnection::ISM_WEBSOCKET, eHostConfig::server, 2080, "ISM_WEBSOCKET");
|
||||
insertConfig(eConnection::FLM_THP_SERVER, eHostConfig::server, 2090, "FLM_THP_SERVER");
|
||||
insertConfig(eConnection::FLM_PDF_SERVER, eHostConfig::server, 3000, "FLM_PDF_SERVER");
|
||||
|
||||
insertConfig(eConnection::LVS, eHostConfig::server, 94, "LVS");
|
||||
insertConfig(eConnection::ZWLVSV, eHostConfig::server, 95, "ZWLVSV");
|
||||
insertConfig(eConnection::ZWLVWCS, eHostConfig::server, 97, "ZWLVWCS");
|
||||
insertConfig(eConnection::ZWLVWMS, eHostConfig::server, 98, "ZWLVWMS");
|
||||
insertConfig(eConnection::ZSLV, eHostConfig::server, 99, "ZSLV");
|
||||
}
|
||||
|
||||
void setIniFile(const QString &iniFileName)
|
||||
{
|
||||
if (!s_settings)
|
||||
qAddPostRoutine(cleanupSettings);
|
||||
delete s_settings;
|
||||
s_settings = new QSettings(iniFileName, QSettings::IniFormat);
|
||||
}
|
||||
|
||||
QString iniFile()
|
||||
{
|
||||
return s_settings ? s_settings->fileName() : QString();
|
||||
}
|
||||
|
||||
unsigned short portOffset()
|
||||
{
|
||||
return s_portOffset;
|
||||
}
|
||||
|
||||
void setPortOffset(unsigned short portOffset)
|
||||
{
|
||||
s_portOffset = portOffset;
|
||||
}
|
||||
|
||||
unsigned short port(eConnection connection)
|
||||
{
|
||||
initConfig();
|
||||
unsigned short port = s_config->value(connection).port;
|
||||
|
||||
if (s_settings)
|
||||
namespace Connections
|
||||
{
|
||||
bool bOk;
|
||||
QString key = s_config->value(connection).name + QLatin1String("/port");
|
||||
unsigned short port2 = s_settings->value(key, port).toString().toUShort(&bOk);
|
||||
if (bOk)
|
||||
port = port2;
|
||||
}
|
||||
if (port < 100)
|
||||
return portOffset() + port;
|
||||
return port;
|
||||
}
|
||||
enum class eHostConfig
|
||||
{
|
||||
public_local,
|
||||
localhost,
|
||||
server,
|
||||
server_avs
|
||||
};
|
||||
struct configStruct
|
||||
{
|
||||
eHostConfig host;
|
||||
unsigned short port;
|
||||
QString name;
|
||||
};
|
||||
|
||||
QString hostName(eConnection connection)
|
||||
{
|
||||
initConfig();
|
||||
static QMap<eConnection, configStruct> *s_config = nullptr;
|
||||
static QSettings *s_settings = nullptr;
|
||||
static unsigned short s_portOffset = 9000;
|
||||
static QString *s_serverHostname = nullptr;
|
||||
|
||||
QString host;
|
||||
switch (s_config->value(connection).host)
|
||||
{
|
||||
case eHostConfig::public_local:
|
||||
host = QString::fromLocal8Bit(qgetenv("HOST"));
|
||||
break;
|
||||
case eHostConfig::localhost:
|
||||
host = QLatin1String("127.0.0.1");
|
||||
break;
|
||||
case eHostConfig::server:
|
||||
if (s_serverHostname)
|
||||
host = *s_serverHostname;
|
||||
if (host.isEmpty())
|
||||
host = QLatin1String("EXCTDS01");
|
||||
break;
|
||||
case eHostConfig::server_avs:
|
||||
host = QStringLiteral("EXCAVS01");
|
||||
break;
|
||||
}
|
||||
if (s_settings)
|
||||
{
|
||||
QString key = s_config->value(connection).name + QLatin1String("/host");
|
||||
QString host2 = s_settings->value(key, host).toString();
|
||||
if (!host2.isEmpty())
|
||||
host = host2;
|
||||
}
|
||||
return host;
|
||||
}
|
||||
static void cleanupSettings()
|
||||
{
|
||||
delete s_settings;
|
||||
s_settings = nullptr;
|
||||
delete s_serverHostname;
|
||||
s_serverHostname = nullptr;
|
||||
delete s_config;
|
||||
s_config = nullptr;
|
||||
}
|
||||
|
||||
void setServerHostname(const QString &serverHostName)
|
||||
{
|
||||
if (!s_serverHostname)
|
||||
s_serverHostname = new QString(serverHostName);
|
||||
else
|
||||
*s_serverHostname = serverHostName;
|
||||
}
|
||||
static void insertConfig(eConnection conn, eHostConfig host, unsigned short port, const char *name)
|
||||
{
|
||||
if (!s_config)
|
||||
s_config = new QMap<eConnection, configStruct>();
|
||||
configStruct s;
|
||||
s.host = host;
|
||||
s.port = port;
|
||||
s.name = QString::fromLatin1(name);
|
||||
s_config->insert(conn, s);
|
||||
}
|
||||
|
||||
QString connectionName(eConnection connection)
|
||||
{
|
||||
if (s_config)
|
||||
{
|
||||
auto it = s_config->constFind(connection);
|
||||
if (it != s_config->constEnd())
|
||||
return it.value().name;
|
||||
static void initConfig()
|
||||
{
|
||||
if (s_config && !s_config->isEmpty())
|
||||
return;
|
||||
|
||||
insertConfig(eConnection::AVS_WORKSTATION, eHostConfig::localhost, 6370, "AVS_WORKSTATION");
|
||||
insertConfig(eConnection::AVS_WORKSTATION_VD, eHostConfig::localhost, 6380, "AVS_WORKSTATION_VD");
|
||||
insertConfig(eConnection::AVS_ROOT, eHostConfig::server_avs, 6350, "AVS_ROOT");
|
||||
insertConfig(eConnection::AVS_FM, eHostConfig::server_avs, 6360, "AVS_FM");
|
||||
insertConfig(eConnection::AVS_MOTION_RECORDER, eHostConfig::server_avs, 6390, "AVS_MOTION_RECORDER");
|
||||
insertConfig(eConnection::AVS_AVA, eHostConfig::server_avs, 6391, "AVS_AVA");
|
||||
|
||||
insertConfig(eConnection::PWS_WEBSOCKET, eHostConfig::server, 5701, "PWS_WEBSOCKET");
|
||||
insertConfig(eConnection::SCM_WEBSOCKET, eHostConfig::server, 7300, "SCM_WEBSOCKET");
|
||||
insertConfig(eConnection::ISM_WEBSOCKET, eHostConfig::server, 2080, "ISM_WEBSOCKET");
|
||||
insertConfig(eConnection::FLM_THP_SERVER, eHostConfig::server, 2090, "FLM_THP_SERVER");
|
||||
insertConfig(eConnection::FLM_PDF_SERVER, eHostConfig::server, 3000, "FLM_PDF_SERVER");
|
||||
|
||||
insertConfig(eConnection::LVS, eHostConfig::server, 94, "LVS");
|
||||
insertConfig(eConnection::ZWLVSV, eHostConfig::server, 95, "ZWLVSV");
|
||||
insertConfig(eConnection::ZWLVWCS, eHostConfig::server, 97, "ZWLVWCS");
|
||||
insertConfig(eConnection::ZWLVWMS, eHostConfig::server, 98, "ZWLVWMS");
|
||||
insertConfig(eConnection::ZSLV, eHostConfig::server, 99, "ZSLV");
|
||||
}
|
||||
|
||||
void setIniFile(const QString &iniFileName)
|
||||
{
|
||||
if (!s_settings)
|
||||
qAddPostRoutine(cleanupSettings);
|
||||
delete s_settings;
|
||||
s_settings = new QSettings(iniFileName, QSettings::IniFormat);
|
||||
}
|
||||
|
||||
QString iniFile()
|
||||
{
|
||||
return s_settings ? s_settings->fileName() : QString();
|
||||
}
|
||||
|
||||
unsigned short portOffset()
|
||||
{
|
||||
return s_portOffset;
|
||||
}
|
||||
|
||||
void setPortOffset(unsigned short portOffset)
|
||||
{
|
||||
s_portOffset = portOffset;
|
||||
}
|
||||
|
||||
unsigned short port(eConnection connection)
|
||||
{
|
||||
initConfig();
|
||||
unsigned short port = s_config->value(connection).port;
|
||||
|
||||
if (s_settings)
|
||||
{
|
||||
bool bOk;
|
||||
QString key = s_config->value(connection).name + QLatin1String("/port");
|
||||
unsigned short port2 = s_settings->value(key, port).toString().toUShort(&bOk);
|
||||
if (bOk)
|
||||
port = port2;
|
||||
}
|
||||
if (port < 100)
|
||||
return portOffset() + port;
|
||||
return port;
|
||||
}
|
||||
|
||||
QString hostName(eConnection connection)
|
||||
{
|
||||
initConfig();
|
||||
|
||||
QString host;
|
||||
switch (s_config->value(connection).host)
|
||||
{
|
||||
case eHostConfig::public_local:
|
||||
host = QString::fromLocal8Bit(qgetenv("HOST"));
|
||||
break;
|
||||
case eHostConfig::localhost:
|
||||
host = QLatin1String("127.0.0.1");
|
||||
break;
|
||||
case eHostConfig::server:
|
||||
if (s_serverHostname)
|
||||
host = *s_serverHostname;
|
||||
if (host.isEmpty())
|
||||
host = QLatin1String("EXCTDS01");
|
||||
break;
|
||||
case eHostConfig::server_avs:
|
||||
host = QStringLiteral("EXCAVS01");
|
||||
break;
|
||||
}
|
||||
if (s_settings)
|
||||
{
|
||||
QString key = s_config->value(connection).name + QLatin1String("/host");
|
||||
QString host2 = s_settings->value(key, host).toString();
|
||||
if (!host2.isEmpty())
|
||||
host = host2;
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
void setServerHostname(const QString &serverHostName)
|
||||
{
|
||||
if (!s_serverHostname)
|
||||
s_serverHostname = new QString(serverHostName);
|
||||
else
|
||||
*s_serverHostname = serverHostName;
|
||||
}
|
||||
|
||||
QString connectionName(eConnection connection)
|
||||
{
|
||||
if (s_config)
|
||||
{
|
||||
auto it = s_config->constFind(connection);
|
||||
if (it != s_config->constEnd())
|
||||
return it.value().name;
|
||||
}
|
||||
return QString::number((int)connection);
|
||||
}
|
||||
}
|
||||
return QString::number((int)connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable → Regular
+32
-34
@@ -9,51 +9,49 @@ namespace NGL
|
||||
{
|
||||
|
||||
|
||||
namespace Connections
|
||||
{
|
||||
namespace Connections
|
||||
{
|
||||
|
||||
|
||||
enum class eConnection
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
AVS_WORKSTATION,
|
||||
AVS_WORKSTATION_VD,
|
||||
AVS_ROOT,
|
||||
AVS_FM,
|
||||
AVS_MOTION_RECORDER,
|
||||
AVS_AVA,
|
||||
ZWLVSV,
|
||||
ZSLV,
|
||||
ZWLVWCS,
|
||||
ZWLVWMS,
|
||||
PWS_WEBSOCKET,
|
||||
SCM_WEBSOCKET,
|
||||
ISM_WEBSOCKET,
|
||||
FLM_THP_SERVER,
|
||||
FLM_PDF_SERVER,
|
||||
LVS ,
|
||||
};
|
||||
enum class eConnection
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
AVS_WORKSTATION,
|
||||
AVS_WORKSTATION_VD,
|
||||
AVS_ROOT,
|
||||
AVS_FM,
|
||||
AVS_MOTION_RECORDER,
|
||||
AVS_AVA,
|
||||
ZWLVSV,
|
||||
ZSLV,
|
||||
ZWLVWCS,
|
||||
ZWLVWMS,
|
||||
PWS_WEBSOCKET,
|
||||
SCM_WEBSOCKET,
|
||||
ISM_WEBSOCKET,
|
||||
FLM_THP_SERVER,
|
||||
FLM_PDF_SERVER,
|
||||
LVS,
|
||||
};
|
||||
|
||||
|
||||
|
||||
NGLSETTINGS_EXPORT void setIniFile(const QString &iniFileName);
|
||||
NGLSETTINGS_EXPORT void setIniFile(const QString &iniFileName);
|
||||
|
||||
|
||||
NGLSETTINGS_EXPORT QString iniFile();
|
||||
NGLSETTINGS_EXPORT QString iniFile();
|
||||
|
||||
|
||||
|
||||
NGLSETTINGS_EXPORT unsigned short portOffset();
|
||||
void setPortOffset(unsigned short portOffset);
|
||||
NGLSETTINGS_EXPORT unsigned short portOffset();
|
||||
void setPortOffset(unsigned short portOffset);
|
||||
|
||||
|
||||
NGLSETTINGS_EXPORT unsigned short port(eConnection connection);
|
||||
NGLSETTINGS_EXPORT unsigned short port(eConnection connection);
|
||||
|
||||
|
||||
NGLSETTINGS_EXPORT QString hostName(eConnection connection);
|
||||
void setServerHostname(const QString &serverHostName);
|
||||
NGLSETTINGS_EXPORT QString hostName(eConnection connection);
|
||||
void setServerHostname(const QString &serverHostName);
|
||||
|
||||
|
||||
NGLSETTINGS_EXPORT QString connectionName(eConnection connection);
|
||||
}
|
||||
}
|
||||
NGLSETTINGS_EXPORT QString connectionName(eConnection connection);
|
||||
}
|
||||
}
|
||||
Executable → Regular
+9
-9
@@ -5,13 +5,13 @@
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef NGLSETTINGS_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLSETTINGS_EXPORT
|
||||
# else
|
||||
# ifdef MAKE_NGLSETTINGS_LIB
|
||||
# define NGLSETTINGS_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define NGLSETTINGS_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLSETTINGS_EXPORT
|
||||
#else
|
||||
#ifdef MAKE_NGLSETTINGS_LIB
|
||||
#define NGLSETTINGS_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define NGLSETTINGS_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+26
-23
@@ -16,20 +16,21 @@ namespace NGL
|
||||
QSettings *Settings::s_globalSettings = nullptr;
|
||||
|
||||
Settings::Settings(const QString &iniFile_)
|
||||
: m_settings(nullptr)
|
||||
: m_settings(nullptr)
|
||||
{
|
||||
QString iniFile = iniFile_;
|
||||
if(iniFile == QLatin1String("gfs_ws.ini")) {
|
||||
if (iniFile == QLatin1String("gfs_ws.ini"))
|
||||
{
|
||||
const QByteArray defUser = qgetenv("USER");
|
||||
if( defUser == "ctc_aar" || defUser == "ctc_rbf" ) {
|
||||
if (defUser == "ctc_aar" || defUser == "ctc_rbf")
|
||||
{
|
||||
QByteArray home = qgetenv("HOME");
|
||||
if(!home.isEmpty()) {
|
||||
QString fn = QString::fromLocal8Bit(home) +
|
||||
QLatin1String("/gfs_") +
|
||||
QString::fromLocal8Bit(defUser.mid(4)) +
|
||||
QLatin1String(".ini");
|
||||
if (!home.isEmpty())
|
||||
{
|
||||
QString fn = QString::fromLocal8Bit(home) + QLatin1String("/gfs_") + QString::fromLocal8Bit(defUser.mid(4)) + QLatin1String(".ini");
|
||||
QFileInfo fi(fn);
|
||||
if(fi.exists() && fi.isFile() && fi.isReadable()) {
|
||||
if (fi.exists() && fi.isFile() && fi.isReadable())
|
||||
{
|
||||
iniFile = fn;
|
||||
}
|
||||
}
|
||||
@@ -39,8 +40,9 @@ namespace NGL
|
||||
initializeGlobalSettings();
|
||||
|
||||
initPre();
|
||||
if(!iniFile.isEmpty()) {
|
||||
if(QFileInfo(iniFile).isAbsolute())
|
||||
if (!iniFile.isEmpty())
|
||||
{
|
||||
if (QFileInfo(iniFile).isAbsolute())
|
||||
m_settings = new QSettings(iniFile, QSettings::IniFormat);
|
||||
else
|
||||
m_settings = new QSettings(basePath() + iniFile, QSettings::IniFormat);
|
||||
@@ -52,7 +54,7 @@ namespace NGL
|
||||
}
|
||||
|
||||
Settings::Settings(const QString &organization, const QString &application)
|
||||
: m_settings(new QSettings(organization, application))
|
||||
: m_settings(new QSettings(organization, application))
|
||||
{
|
||||
initPre();
|
||||
initPost();
|
||||
@@ -71,8 +73,8 @@ namespace NGL
|
||||
if (!s_globalSettings)
|
||||
{
|
||||
QString globalSettingsFile = NGL::findProjectConfigFile();
|
||||
|
||||
|
||||
|
||||
|
||||
if (!globalSettingsFile.isEmpty())
|
||||
s_globalSettings = new QSettings(globalSettingsFile, QSettings::IniFormat);
|
||||
}
|
||||
@@ -141,7 +143,7 @@ namespace NGL
|
||||
{
|
||||
initializeGlobalSettings();
|
||||
|
||||
return s_globalSettings->value(globalSectionName()+ QLatin1String("/DatabaseName"), QLatin1String("lts_ets_pro")).toString();
|
||||
return s_globalSettings->value(globalSectionName() + QLatin1String("/DatabaseName"), QLatin1String("lts_ets_pro")).toString();
|
||||
}
|
||||
|
||||
QString Settings::databaseHostname()
|
||||
@@ -209,23 +211,24 @@ namespace NGL
|
||||
QString Settings::fixupPath(const QString &_path) const
|
||||
{
|
||||
QString path = QDir::fromNativeSeparators(_path);
|
||||
if(!QDir::isAbsolutePath(path))
|
||||
if (!QDir::isAbsolutePath(path))
|
||||
path = basePath() + path;
|
||||
path = QDir::cleanPath(path);
|
||||
if(!path.endsWith(QLatin1Char('/')))
|
||||
if (!path.endsWith(QLatin1Char('/')))
|
||||
path += QLatin1Char('/');
|
||||
return path;
|
||||
}
|
||||
|
||||
QString Settings::getDirectory(const QByteArray &_dir, const QString &defPrefix, bool bPathLowercase)
|
||||
{
|
||||
if(m_paths[_dir].isEmpty()) {
|
||||
if (m_paths[_dir].isEmpty())
|
||||
{
|
||||
const QString lowerDir = QString::fromLatin1(_dir.toLower());
|
||||
const QString dir = bPathLowercase ? lowerDir : QString::fromLatin1(_dir);
|
||||
QString def = defPrefix + QLatin1Char('/') + dir + QLatin1Char('/');
|
||||
m_paths[_dir] = fixupPath(m_settings->value(QLatin1String("paths/") + lowerDir, def).toString());
|
||||
QDir d(m_paths[_dir]);
|
||||
if(!d.exists())
|
||||
if (!d.exists())
|
||||
d.mkpath(d.absolutePath());
|
||||
}
|
||||
return m_paths[_dir];
|
||||
@@ -235,18 +238,18 @@ namespace NGL
|
||||
{
|
||||
#ifdef WIN32
|
||||
QString path = QString::fromLocal8Bit(qgetenv("GFS_PATH"));
|
||||
if(path.isEmpty())
|
||||
if (path.isEmpty())
|
||||
path = QCoreApplication::applicationDirPath();
|
||||
m_paths["GFS_PATH"] = fixupPath(path);
|
||||
#else
|
||||
QByteArray path = qgetenv("GFS_PATH");
|
||||
if(path.isEmpty())
|
||||
if (path.isEmpty())
|
||||
path = qgetenv("HOME");
|
||||
m_paths["GFS_PATH"] = fixupPath(QString::fromLocal8Bit(path));
|
||||
#endif
|
||||
|
||||
QByteArray tmppath = qgetenv("TMP_PATH");
|
||||
if(tmppath.isEmpty())
|
||||
if (tmppath.isEmpty())
|
||||
tmppath = qgetenv("TMP");
|
||||
if (tmppath.isEmpty())
|
||||
tmppath = QDir::tempPath().toLocal8Bit();
|
||||
@@ -317,4 +320,4 @@ namespace NGL
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Executable → Regular
+85
-105
@@ -8,135 +8,115 @@
|
||||
|
||||
class QSettings;
|
||||
|
||||
namespace NGL {
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
class NGLSETTINGS_EXPORT Settings {
|
||||
public:
|
||||
|
||||
|
||||
explicit Settings(const QString &iniFile);
|
||||
class NGLSETTINGS_EXPORT Settings
|
||||
{
|
||||
public:
|
||||
explicit Settings(const QString &iniFile);
|
||||
|
||||
|
||||
|
||||
explicit Settings(const QString &organization, const QString &application);
|
||||
|
||||
Settings(const Settings&) = delete;
|
||||
Settings &operator=(const Settings&) = delete;
|
||||
explicit Settings(const QString &organization, const QString &application);
|
||||
|
||||
|
||||
Settings(const Settings &) = delete;
|
||||
Settings &operator=(const Settings &) = delete;
|
||||
|
||||
virtual ~Settings();
|
||||
|
||||
|
||||
static void initializeGlobalSettings();
|
||||
virtual ~Settings();
|
||||
|
||||
|
||||
QString basePath() const;
|
||||
|
||||
QString tempPath() const;
|
||||
|
||||
QString printPath();
|
||||
|
||||
QString logoProject();
|
||||
|
||||
QString bitmapPath();
|
||||
|
||||
|
||||
|
||||
QString zsks_rxPath();
|
||||
|
||||
QString zsks_txPath();
|
||||
static void initializeGlobalSettings();
|
||||
|
||||
|
||||
|
||||
static QString databaseName();
|
||||
|
||||
static QString databaseHostname();
|
||||
|
||||
QString databaseUser();
|
||||
|
||||
QString databasePassword(const QString &databaseUser = QString());
|
||||
|
||||
QString databaseDriver();
|
||||
|
||||
|
||||
|
||||
QString aarServerPath(int exerciseId);
|
||||
bool isDatabaseConnectionLocal();
|
||||
QString basePath() const;
|
||||
|
||||
|
||||
int avsKeepAliveTimeout();
|
||||
QString avsServerHost();
|
||||
quint16 avsServerPortAVE();
|
||||
QString tempPath() const;
|
||||
|
||||
|
||||
QSettings *settings();
|
||||
|
||||
const QSettings *settings() const;
|
||||
QString printPath();
|
||||
|
||||
|
||||
int getInteger(const QString &key, int defVal) const;
|
||||
QString logoProject();
|
||||
|
||||
|
||||
int getInteger(const QString &group, const QString &key, int defVal) const
|
||||
{
|
||||
return getInteger(group + QLatin1Char('/') + key, defVal);
|
||||
}
|
||||
QString bitmapPath();
|
||||
|
||||
|
||||
float getFloat(const QString &key, float defVal) const;
|
||||
|
||||
|
||||
float getFloat(const QString &group, const QString &key, float defVal) const
|
||||
{
|
||||
return getFloat(group + QLatin1Char('/') + key, defVal);
|
||||
}
|
||||
QString zsks_rxPath();
|
||||
|
||||
|
||||
double getDouble(const QString &key, double defVal) const;
|
||||
QString zsks_txPath();
|
||||
|
||||
|
||||
double getDouble(const QString &group, const QString &key, double defVal) const
|
||||
{
|
||||
return getDouble(group + QLatin1Char('/') + key, defVal);
|
||||
}
|
||||
|
||||
|
||||
bool getBoolean(const QString &key, bool defVal) const;
|
||||
static QString databaseName();
|
||||
|
||||
|
||||
bool getBoolean(const QString &group, const QString &key, bool defVal) const
|
||||
{
|
||||
return getBoolean(group + QLatin1Char('/') + key, defVal);
|
||||
}
|
||||
static QString databaseHostname();
|
||||
|
||||
|
||||
QString getString(const QString &key, const QString &defVal) const;
|
||||
QString databaseUser();
|
||||
|
||||
|
||||
QString getString(const QString &group, const QString &key, const QString &defVal) const
|
||||
{
|
||||
return getString(group + QLatin1Char('/') + key, defVal);
|
||||
}
|
||||
QString databasePassword(const QString &databaseUser = QString());
|
||||
|
||||
static unsigned short portOffset();
|
||||
static unsigned short domainId();
|
||||
static QString serverHostname();
|
||||
static QString logPath();
|
||||
static QString globalSectionName();
|
||||
QString databaseDriver();
|
||||
|
||||
private:
|
||||
|
||||
QString fixupPath(const QString &path) const;
|
||||
|
||||
|
||||
QString getDirectory(const QByteArray &dir, const QString &defPrefix, bool bPathLowercase = false);
|
||||
private:
|
||||
void initPre();
|
||||
void initPost();
|
||||
QSettings *m_settings;
|
||||
static QSettings *s_globalSettings;
|
||||
QHash<QByteArray, QString> m_paths;
|
||||
QString aarServerPath(int exerciseId);
|
||||
bool isDatabaseConnectionLocal();
|
||||
|
||||
|
||||
int avsKeepAliveTimeout();
|
||||
QString avsServerHost();
|
||||
quint16 avsServerPortAVE();
|
||||
|
||||
|
||||
QSettings *settings();
|
||||
|
||||
const QSettings *settings() const;
|
||||
|
||||
|
||||
int getInteger(const QString &key, int defVal) const;
|
||||
|
||||
|
||||
int getInteger(const QString &group, const QString &key, int defVal) const { return getInteger(group + QLatin1Char('/') + key, defVal); }
|
||||
|
||||
|
||||
float getFloat(const QString &key, float defVal) const;
|
||||
|
||||
|
||||
float getFloat(const QString &group, const QString &key, float defVal) const { return getFloat(group + QLatin1Char('/') + key, defVal); }
|
||||
|
||||
|
||||
double getDouble(const QString &key, double defVal) const;
|
||||
|
||||
|
||||
double getDouble(const QString &group, const QString &key, double defVal) const { return getDouble(group + QLatin1Char('/') + key, defVal); }
|
||||
|
||||
|
||||
bool getBoolean(const QString &key, bool defVal) const;
|
||||
|
||||
|
||||
bool getBoolean(const QString &group, const QString &key, bool defVal) const { return getBoolean(group + QLatin1Char('/') + key, defVal); }
|
||||
|
||||
|
||||
QString getString(const QString &key, const QString &defVal) const;
|
||||
|
||||
|
||||
QString getString(const QString &group, const QString &key, const QString &defVal) const { return getString(group + QLatin1Char('/') + key, defVal); }
|
||||
|
||||
static unsigned short portOffset();
|
||||
static unsigned short domainId();
|
||||
static QString serverHostname();
|
||||
static QString logPath();
|
||||
static QString globalSectionName();
|
||||
|
||||
private:
|
||||
QString fixupPath(const QString &path) const;
|
||||
|
||||
|
||||
QString getDirectory(const QByteArray &dir, const QString &defPrefix, bool bPathLowercase = false);
|
||||
|
||||
private:
|
||||
void initPre();
|
||||
void initPost();
|
||||
QSettings *m_settings;
|
||||
static QSettings *s_globalSettings;
|
||||
QHash<QByteArray, QString> m_paths;
|
||||
};
|
||||
}
|
||||
}
|
||||
Executable → Regular
+32
-41
@@ -3,33 +3,33 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace NGL {
|
||||
template<class T>
|
||||
class BitSet {
|
||||
namespace NGL
|
||||
{
|
||||
template <class T> class BitSet
|
||||
{
|
||||
public:
|
||||
BitSet(T bitset = T())
|
||||
: mBitSet(bitset)
|
||||
, mSize(sizeof(T)*8)
|
||||
{}
|
||||
: mBitSet(bitset)
|
||||
, mSize(sizeof(T) * 8)
|
||||
{
|
||||
}
|
||||
BitSet(const BitSet<T> &other)
|
||||
: mBitSet(other.mBitSet)
|
||||
, mSize(other.mSize)
|
||||
{}
|
||||
: mBitSet(other.mBitSet)
|
||||
, mSize(other.mSize)
|
||||
{
|
||||
}
|
||||
BitSet &operator=(const BitSet<T> &other)
|
||||
{
|
||||
if(this == &other)
|
||||
if (this == &other)
|
||||
return *this;
|
||||
mBitSet = other.mBitSet;
|
||||
mSize = other.mSize;
|
||||
return *this;
|
||||
}
|
||||
bool operator==(const BitSet<T> &other) const
|
||||
{
|
||||
return (mBitSet == other.mBitSet && mSize == other.mSize);
|
||||
}
|
||||
bool operator==(const BitSet<T> &other) const { return (mBitSet == other.mBitSet && mSize == other.mSize); }
|
||||
bool setBit(unsigned int bitNum)
|
||||
{
|
||||
if(bitNum >= mSize)
|
||||
if (bitNum >= mSize)
|
||||
return false;
|
||||
mBitSet |= getBit(bitNum);
|
||||
return true;
|
||||
@@ -37,55 +37,46 @@ namespace NGL {
|
||||
|
||||
bool clearBit(unsigned int bitNum)
|
||||
{
|
||||
if(bitNum >= mSize)
|
||||
if (bitNum >= mSize)
|
||||
return false;
|
||||
mBitSet &= ~(getBit(bitNum));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool at(unsigned int bitNum) const
|
||||
{
|
||||
if(bitNum >= sizeof(T) * 8)
|
||||
if (bitNum >= sizeof(T) * 8)
|
||||
return false;
|
||||
T compVal = getBit(bitNum);
|
||||
return ((mBitSet & compVal) == compVal);
|
||||
}
|
||||
|
||||
bool operator[] (unsigned int bitNum) const
|
||||
{
|
||||
return at(bitNum);
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return mSize;
|
||||
}
|
||||
|
||||
|
||||
bool operator[](unsigned int bitNum) const { return at(bitNum); }
|
||||
|
||||
size_t size() const { return mSize; }
|
||||
|
||||
bool resize(size_t newSize)
|
||||
{
|
||||
if(newSize >= sizeof(T) * 8)
|
||||
if (newSize >= sizeof(T) * 8)
|
||||
return false;
|
||||
for(unsigned int i = mSize; i < newSize; ++i)
|
||||
for (unsigned int i = mSize; i < newSize; ++i)
|
||||
clearBit(i);
|
||||
mSize = newSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
fill(false);
|
||||
}
|
||||
|
||||
|
||||
void clear() { fill(false); }
|
||||
|
||||
void fill(bool bBitsSet)
|
||||
{
|
||||
if(bBitsSet)
|
||||
if (bBitsSet)
|
||||
mBitSet = ~T();
|
||||
else
|
||||
mBitSet = T();
|
||||
}
|
||||
|
||||
|
||||
T operator()() const { return mBitSet; }
|
||||
|
||||
|
||||
protected:
|
||||
static T getBit(unsigned int bitNum_)
|
||||
{
|
||||
@@ -97,4 +88,4 @@ namespace NGL {
|
||||
T mBitSet;
|
||||
size_t mSize;
|
||||
};
|
||||
}
|
||||
}
|
||||
Executable → Regular
+67
-67
@@ -4,88 +4,88 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
QByteArray quoteForTelnet(const QVector<QString> &sl)
|
||||
{
|
||||
QVector<QByteArray> tmp;
|
||||
tmp.reserve(sl.size());
|
||||
for (const QString &s : sl)
|
||||
tmp += s.toUtf8();
|
||||
return quoteForTelnet(tmp);
|
||||
}
|
||||
|
||||
QByteArray quoteForTelnet(const QVector<QByteArray> &sl)
|
||||
{
|
||||
QByteArray cmd;
|
||||
for (QByteArray s : sl)
|
||||
QByteArray quoteForTelnet(const QVector<QString> &sl)
|
||||
{
|
||||
s.replace('\"', "\\\"");
|
||||
if (s.contains(' '))
|
||||
s = '"' + s + '"';
|
||||
if (s.isEmpty())
|
||||
s = "\"\"";
|
||||
cmd += s + ' ';
|
||||
QVector<QByteArray> tmp;
|
||||
tmp.reserve(sl.size());
|
||||
for (const QString &s : sl)
|
||||
tmp += s.toUtf8();
|
||||
return quoteForTelnet(tmp);
|
||||
}
|
||||
cmd += '\n';
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
QVector<QByteArray> parseFromTelnet(const QByteArray &ba, const int iStart)
|
||||
{
|
||||
QVector<QByteArray> ret;
|
||||
const char *p = ba.constData() + iStart;
|
||||
const int iLen = ba.length();
|
||||
const char *p_end = ba.constData() + iLen;
|
||||
if (iLen <= iStart)
|
||||
return ret;
|
||||
char quoteEndChar = '"';
|
||||
|
||||
while (p < p_end && *p)
|
||||
QByteArray quoteForTelnet(const QVector<QByteArray> &sl)
|
||||
{
|
||||
while (isspace(*p))
|
||||
++p;
|
||||
if (*p && p < p_end)
|
||||
QByteArray cmd;
|
||||
for (QByteArray s : sl)
|
||||
{
|
||||
bool escaped = false;
|
||||
bool bQuoted = (*p == '\"') || (*p == '{');
|
||||
if (bQuoted)
|
||||
{
|
||||
quoteEndChar = (*p == '\"') ? '\"' : '}';
|
||||
s.replace('\"', "\\\"");
|
||||
if (s.contains(' '))
|
||||
s = '"' + s + '"';
|
||||
if (s.isEmpty())
|
||||
s = "\"\"";
|
||||
cmd += s + ' ';
|
||||
}
|
||||
cmd += '\n';
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
QVector<QByteArray> parseFromTelnet(const QByteArray &ba, const int iStart)
|
||||
{
|
||||
QVector<QByteArray> ret;
|
||||
const char *p = ba.constData() + iStart;
|
||||
const int iLen = ba.length();
|
||||
const char *p_end = ba.constData() + iLen;
|
||||
if (iLen <= iStart)
|
||||
return ret;
|
||||
char quoteEndChar = '"';
|
||||
|
||||
while (p < p_end && *p)
|
||||
{
|
||||
while (isspace(*p))
|
||||
++p;
|
||||
}
|
||||
const char *start = p;
|
||||
while (true)
|
||||
if (*p && p < p_end)
|
||||
{
|
||||
while (p < p_end && *p != (bQuoted ? quoteEndChar : ' '))
|
||||
++p;
|
||||
bool escaped = false;
|
||||
bool bQuoted = (*p == '\"') || (*p == '{');
|
||||
if (bQuoted)
|
||||
{
|
||||
|
||||
if (* (p - 1) == '\\')
|
||||
{
|
||||
++p;
|
||||
escaped = true;
|
||||
continue;
|
||||
}
|
||||
quoteEndChar = (*p == '\"') ? '\"' : '}';
|
||||
++p;
|
||||
}
|
||||
QByteArray result = QByteArray(start, p - start).trimmed();
|
||||
if (escaped)
|
||||
const char *start = p;
|
||||
while (true)
|
||||
{
|
||||
if (quoteEndChar == '}')
|
||||
while (p < p_end && *p != (bQuoted ? quoteEndChar : ' '))
|
||||
++p;
|
||||
if (bQuoted)
|
||||
{
|
||||
result = result.replace("\\{", "{");
|
||||
result = result.replace("\\}", "}");
|
||||
|
||||
if (*(p - 1) == '\\')
|
||||
{
|
||||
++p;
|
||||
escaped = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
result = result.replace("\\\"", "\"");
|
||||
QByteArray result = QByteArray(start, p - start).trimmed();
|
||||
if (escaped)
|
||||
{
|
||||
if (quoteEndChar == '}')
|
||||
{
|
||||
result = result.replace("\\{", "{");
|
||||
result = result.replace("\\}", "}");
|
||||
}
|
||||
else
|
||||
result = result.replace("\\\"", "\"");
|
||||
}
|
||||
ret += result;
|
||||
++p;
|
||||
break;
|
||||
}
|
||||
ret += result;
|
||||
++p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Executable → Regular
+3
-7
@@ -11,13 +11,9 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
NGLTOOLS_EXPORT QByteArray quoteForTelnet(const QVector<QString> &sl);
|
||||
NGLTOOLS_EXPORT QByteArray quoteForTelnet(const QVector<QByteArray> &sl);
|
||||
NGLTOOLS_EXPORT QByteArray quoteForTelnet(const QVector<QString> &sl);
|
||||
NGLTOOLS_EXPORT QByteArray quoteForTelnet(const QVector<QByteArray> &sl);
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT QVector<QByteArray> parseFromTelnet(const QByteArray &ba, const int iStart = 0);
|
||||
NGLTOOLS_EXPORT QVector<QByteArray> parseFromTelnet(const QByteArray &ba, const int iStart = 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+317
-322
@@ -7,367 +7,362 @@
|
||||
namespace DTG
|
||||
{
|
||||
|
||||
static char s_timezone = 'Z';
|
||||
static char s_userDefinedTimezone = s_timezone;
|
||||
static char s_exerciseDefaultTimezone = s_timezone;
|
||||
int timezone2Hours(char tz, bool *bOk)
|
||||
{
|
||||
if (!isTimezoneValid(tz))
|
||||
static char s_timezone = 'Z';
|
||||
static char s_userDefinedTimezone = s_timezone;
|
||||
static char s_exerciseDefaultTimezone = s_timezone;
|
||||
int timezone2Hours(char tz, bool *bOk)
|
||||
{
|
||||
if (!isTimezoneValid(tz))
|
||||
{
|
||||
if (bOk)
|
||||
*bOk = false;
|
||||
return 0;
|
||||
}
|
||||
if (bOk)
|
||||
*bOk = false;
|
||||
*bOk = true;
|
||||
if (tz < 'J')
|
||||
return tz - 'A' + 1;
|
||||
if (tz < 'N')
|
||||
return tz - 'A';
|
||||
if (tz < 'Z')
|
||||
return 'Z' - tz - 13;
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (bOk)
|
||||
*bOk = true;
|
||||
if (tz < 'J')
|
||||
return tz - 'A' + 1;
|
||||
if (tz < 'N')
|
||||
return tz - 'A';
|
||||
if (tz < 'Z')
|
||||
return 'Z' - tz - 13;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int timezone2Secs(char tz, bool *bOk)
|
||||
{
|
||||
return 3600 * timezone2Hours(tz, bOk) ;
|
||||
}
|
||||
|
||||
|
||||
bool setTimezone(char tz, bool bUserDefinedZone)
|
||||
{
|
||||
if (!isTimezoneValid(tz))
|
||||
int timezone2Secs(char tz, bool *bOk)
|
||||
{
|
||||
|
||||
if (!(tz == 0 && bUserDefinedZone))
|
||||
return false;
|
||||
return 3600 * timezone2Hours(tz, bOk);
|
||||
}
|
||||
if (bUserDefinedZone)
|
||||
s_userDefinedTimezone = tz;
|
||||
else
|
||||
s_exerciseDefaultTimezone = tz;
|
||||
|
||||
s_timezone = s_userDefinedTimezone != 0 ? s_userDefinedTimezone : s_exerciseDefaultTimezone;
|
||||
return true;
|
||||
}
|
||||
|
||||
char timezone()
|
||||
{
|
||||
return s_timezone;
|
||||
}
|
||||
char timezoneUserDefined()
|
||||
{
|
||||
return s_userDefinedTimezone;
|
||||
}
|
||||
char timezoneExerciseDefault()
|
||||
{
|
||||
return s_exerciseDefaultTimezone;
|
||||
}
|
||||
|
||||
bool isTimezoneValid(char tz)
|
||||
{
|
||||
tz = toupper(tz);
|
||||
return !(tz < 'A' || tz == 'J' || tz > 'Z');
|
||||
}
|
||||
|
||||
|
||||
|
||||
static DateTimeType s_dateTimeType = DDMMYYYY_Z_HHMMSS;
|
||||
static DisplayFormat s_defaultDisplayFormat = Long;
|
||||
|
||||
|
||||
void setDateTimeType(DateTimeType dtType)
|
||||
{
|
||||
s_dateTimeType = dtType;
|
||||
}
|
||||
|
||||
DateTimeType dateTimeType()
|
||||
{
|
||||
return s_dateTimeType;
|
||||
}
|
||||
|
||||
void setDefaultDisplayFormat(DisplayFormat dtFormat)
|
||||
{
|
||||
s_defaultDisplayFormat = dtFormat;
|
||||
}
|
||||
|
||||
DisplayFormat defaultDisplayFormat()
|
||||
{
|
||||
return s_defaultDisplayFormat;
|
||||
}
|
||||
|
||||
QString toString(const QDateTime &dt, DisplayFormat format, DateTimeType type)
|
||||
{
|
||||
if (format == Default)
|
||||
format = s_defaultDisplayFormat;
|
||||
static const QDateTime dtNull = QDateTime::fromSecsSinceEpoch(0);
|
||||
if (!dt.isValid() || dt == dtNull)
|
||||
return QString();
|
||||
|
||||
const QDateTime dateTime = dt.toUTC().addSecs(timezone2Hours(s_timezone) * 3600);
|
||||
QString ret;
|
||||
|
||||
switch (type)
|
||||
bool setTimezone(char tz, bool bUserDefinedZone)
|
||||
{
|
||||
case DTG:
|
||||
{
|
||||
|
||||
|
||||
|
||||
QString str1;
|
||||
|
||||
if (format == Long)
|
||||
str1 = dateTime.toString(QLatin1String("dd hhmmss"));
|
||||
else if (format == TurboLong)
|
||||
str1 = dateTime.toString(QLatin1String("dd hhmmss.z"));
|
||||
else
|
||||
if (!isTimezoneValid(tz))
|
||||
{
|
||||
ret = dateTime.toString(QLatin1String("ddhhmm")) + QLatin1Char(s_timezone);
|
||||
|
||||
if (!(tz == 0 && bUserDefinedZone))
|
||||
return false;
|
||||
}
|
||||
if (bUserDefinedZone)
|
||||
s_userDefinedTimezone = tz;
|
||||
else
|
||||
s_exerciseDefaultTimezone = tz;
|
||||
|
||||
s_timezone = s_userDefinedTimezone != 0 ? s_userDefinedTimezone : s_exerciseDefaultTimezone;
|
||||
return true;
|
||||
}
|
||||
|
||||
char timezone()
|
||||
{
|
||||
return s_timezone;
|
||||
}
|
||||
char timezoneUserDefined()
|
||||
{
|
||||
return s_userDefinedTimezone;
|
||||
}
|
||||
char timezoneExerciseDefault()
|
||||
{
|
||||
return s_exerciseDefaultTimezone;
|
||||
}
|
||||
|
||||
bool isTimezoneValid(char tz)
|
||||
{
|
||||
tz = toupper(tz);
|
||||
return !(tz < 'A' || tz == 'J' || tz > 'Z');
|
||||
}
|
||||
|
||||
|
||||
static DateTimeType s_dateTimeType = DDMMYYYY_Z_HHMMSS;
|
||||
static DisplayFormat s_defaultDisplayFormat = Long;
|
||||
|
||||
|
||||
void setDateTimeType(DateTimeType dtType)
|
||||
{
|
||||
s_dateTimeType = dtType;
|
||||
}
|
||||
|
||||
DateTimeType dateTimeType()
|
||||
{
|
||||
return s_dateTimeType;
|
||||
}
|
||||
|
||||
void setDefaultDisplayFormat(DisplayFormat dtFormat)
|
||||
{
|
||||
s_defaultDisplayFormat = dtFormat;
|
||||
}
|
||||
|
||||
DisplayFormat defaultDisplayFormat()
|
||||
{
|
||||
return s_defaultDisplayFormat;
|
||||
}
|
||||
|
||||
QString toString(const QDateTime &dt, DisplayFormat format, DateTimeType type)
|
||||
{
|
||||
if (format == Default)
|
||||
format = s_defaultDisplayFormat;
|
||||
static const QDateTime dtNull = QDateTime::fromSecsSinceEpoch(0);
|
||||
if (!dt.isValid() || dt == dtNull)
|
||||
return QString();
|
||||
|
||||
const QDateTime dateTime = dt.toUTC().addSecs(timezone2Hours(s_timezone) * 3600);
|
||||
QString ret;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DTG:
|
||||
{
|
||||
|
||||
|
||||
QString str1;
|
||||
|
||||
if (format == Long)
|
||||
str1 = dateTime.toString(QLatin1String("dd hhmmss"));
|
||||
else if (format == TurboLong)
|
||||
str1 = dateTime.toString(QLatin1String("dd hhmmss.z"));
|
||||
else
|
||||
{
|
||||
ret = dateTime.toString(QLatin1String("ddhhmm")) + QLatin1Char(s_timezone);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
const int month = dateTime.date().month() - 1;
|
||||
const int year = dateTime.date().year() - 2000;
|
||||
ret = QStringLiteral("%1 %2 %3 %4").arg(str1).arg(QLatin1Char(s_timezone)).arg(months().at(month)).arg(year, 2, 10, QLatin1Char('0'));
|
||||
}
|
||||
break;
|
||||
case DDMMYYYY_HHMMSS_Z:
|
||||
{
|
||||
if (format == Long)
|
||||
ret = dateTime.toString(QLatin1String("dd.MM.yyyy HH:mm:ss")) + QLatin1Char(s_timezone);
|
||||
else
|
||||
ret = dateTime.toString(QLatin1String("dd.MM HH:mm")) + QLatin1Char(s_timezone);
|
||||
}
|
||||
break;
|
||||
case DDMMYYYY_Z_HHMMSS:
|
||||
if (format == Long)
|
||||
ret = dateTime.toString(QLatin1String("dd.MM.yyyy ")) + QLatin1Char(s_timezone) + dateTime.toString(QLatin1String(" HH:mm:ss"));
|
||||
else
|
||||
ret = dateTime.toString(QLatin1String("dd.MM ")) + QLatin1Char(s_timezone) + dateTime.toString(QLatin1String(" HH:mm"));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
const int month = dateTime.date().month() - 1;
|
||||
const int year = dateTime.date().year() - 2000;
|
||||
ret = QStringLiteral("%1 %2 %3 %4")
|
||||
.arg(str1)
|
||||
.arg(QLatin1Char(s_timezone))
|
||||
.arg(months().at(month))
|
||||
.arg(year, 2, 10, QLatin1Char('0'));
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
case DDMMYYYY_HHMMSS_Z:
|
||||
{
|
||||
if (format == Long)
|
||||
ret = dateTime.toString(QLatin1String("dd.MM.yyyy HH:mm:ss")) + QLatin1Char(s_timezone);
|
||||
else
|
||||
ret = dateTime.toString(QLatin1String("dd.MM HH:mm")) + QLatin1Char(s_timezone);
|
||||
|
||||
QString toStringMSec(qint64 msecSinceEpoch, DisplayFormat format)
|
||||
{
|
||||
if (msecSinceEpoch <= 0)
|
||||
return QString();
|
||||
return toString(QDateTime::fromMSecsSinceEpoch(msecSinceEpoch), format);
|
||||
}
|
||||
break;
|
||||
case DDMMYYYY_Z_HHMMSS:
|
||||
if (format == Long)
|
||||
ret = dateTime.toString(QLatin1String("dd.MM.yyyy "))
|
||||
+ QLatin1Char(s_timezone)
|
||||
+ dateTime.toString(QLatin1String(" HH:mm:ss"));
|
||||
else
|
||||
ret = dateTime.toString(QLatin1String("dd.MM "))
|
||||
+ QLatin1Char(s_timezone)
|
||||
+ dateTime.toString(QLatin1String(" HH:mm"));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString toStringMSec(qint64 msecSinceEpoch, DisplayFormat format)
|
||||
{
|
||||
if (msecSinceEpoch <= 0)
|
||||
return QString();
|
||||
return toString(QDateTime::fromMSecsSinceEpoch(msecSinceEpoch), format);
|
||||
}
|
||||
|
||||
|
||||
static bool check24(const QChar *input, int *output)
|
||||
{
|
||||
const int i1 = input[0].unicode() - '0';
|
||||
const int i2 = input[1].unicode() - '0';
|
||||
if (i1 > 2)
|
||||
return false;
|
||||
if (i1 == 2 && i2 > 5)
|
||||
return false;
|
||||
if (output)
|
||||
*output = i1 * 10 + i2;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool check31(const QChar *input, int *output = nullptr)
|
||||
{
|
||||
const int i1 = input[0].unicode() - '0';
|
||||
const int i2 = input[1].unicode() - '0';
|
||||
if (i1 > 3)
|
||||
return false;
|
||||
if (i1 == 3 && i2 > 1)
|
||||
return false;
|
||||
if (output)
|
||||
*output = i1 * 10 + i2;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool check60(const QChar *input, int *output)
|
||||
{
|
||||
const int i1 = input[0].unicode() - '0';
|
||||
const int i2 = input[1].unicode() - '0';
|
||||
if (i1 > 5)
|
||||
return false;
|
||||
if (output)
|
||||
*output = i1 * 10 + i2;
|
||||
return true;
|
||||
}
|
||||
|
||||
static DTGValidation validate18(const QString &input, QDateTime &dt)
|
||||
{
|
||||
int hh, mm, ss;
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
static bool check24(const QChar *input, int *output)
|
||||
{
|
||||
if (!input[i].isDigit())
|
||||
return Invalid;
|
||||
const int i1 = input[0].unicode() - '0';
|
||||
const int i2 = input[1].unicode() - '0';
|
||||
if (i1 > 2)
|
||||
return false;
|
||||
if (i1 == 2 && i2 > 5)
|
||||
return false;
|
||||
if (output)
|
||||
*output = i1 * 10 + i2;
|
||||
return true;
|
||||
}
|
||||
if (!check31(&input.data() [0]))
|
||||
return Invalid;
|
||||
|
||||
if (input[2] != QLatin1Char(' '))
|
||||
return Invalid;
|
||||
|
||||
if (input.length() == 7)
|
||||
static bool check31(const QChar *input, int *output = nullptr)
|
||||
{
|
||||
for (int i = 3; i < 7; ++i)
|
||||
const int i1 = input[0].unicode() - '0';
|
||||
const int i2 = input[1].unicode() - '0';
|
||||
if (i1 > 3)
|
||||
return false;
|
||||
if (i1 == 3 && i2 > 1)
|
||||
return false;
|
||||
if (output)
|
||||
*output = i1 * 10 + i2;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool check60(const QChar *input, int *output)
|
||||
{
|
||||
const int i1 = input[0].unicode() - '0';
|
||||
const int i2 = input[1].unicode() - '0';
|
||||
if (i1 > 5)
|
||||
return false;
|
||||
if (output)
|
||||
*output = i1 * 10 + i2;
|
||||
return true;
|
||||
}
|
||||
|
||||
static DTGValidation validate18(const QString &input, QDateTime &dt)
|
||||
{
|
||||
int hh, mm, ss;
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (!input[i].isDigit())
|
||||
return Invalid;
|
||||
}
|
||||
return Intermediate;
|
||||
}
|
||||
for (int i = 3; i < 9; ++i)
|
||||
{
|
||||
if (!input[i].isDigit())
|
||||
if (!check31(&input.data()[0]))
|
||||
return Invalid;
|
||||
}
|
||||
if (!check24(&input.data() [3], &hh))
|
||||
return Invalid;
|
||||
if (!check60(&input.data() [5], &mm))
|
||||
return Invalid;
|
||||
if (!check60(&input.data() [7], &ss))
|
||||
return Invalid;
|
||||
|
||||
if (input[9] != QLatin1Char(' '))
|
||||
return Invalid;
|
||||
|
||||
const QChar c = input[10];
|
||||
if (c < QLatin1Char('A') || c > QLatin1Char('Z'))
|
||||
return Invalid;
|
||||
if (c == QLatin1Char('J'))
|
||||
{
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
const QString mon = input.mid(12, 3);
|
||||
int month = months().indexOf(mon);
|
||||
if (month < 0)
|
||||
{
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
for (int i = 16; i < 18; ++i)
|
||||
{
|
||||
if (!input[i].isDigit())
|
||||
if (input[2] != QLatin1Char(' '))
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
|
||||
const int day = input.left(2).toInt();
|
||||
const int year = input.mid(16, 2).toInt() + 2000;
|
||||
dt = QDateTime(QDate(year, month + 1, day), QTime(hh, mm, ss), QTimeZone::utc());
|
||||
if (!dt.isValid())
|
||||
{
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
dt = dt.addSecs(-timezone2Hours(c.toLatin1()) * 3600);
|
||||
|
||||
|
||||
return Acceptable;
|
||||
}
|
||||
|
||||
static DTGValidation validate7(const QString &input, QDateTime &dt)
|
||||
{
|
||||
int hh, mm;
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
if (!input[i].isDigit())
|
||||
if (input.length() == 7)
|
||||
{
|
||||
for (int i = 3; i < 7; ++i)
|
||||
{
|
||||
if (!input[i].isDigit())
|
||||
return Invalid;
|
||||
}
|
||||
return Intermediate;
|
||||
}
|
||||
for (int i = 3; i < 9; ++i)
|
||||
{
|
||||
if (!input[i].isDigit())
|
||||
return Invalid;
|
||||
}
|
||||
if (!check24(&input.data()[3], &hh))
|
||||
return Invalid;
|
||||
if (!check60(&input.data()[5], &mm))
|
||||
return Invalid;
|
||||
if (!check60(&input.data()[7], &ss))
|
||||
return Invalid;
|
||||
}
|
||||
if (!check31(&input.data() [0]))
|
||||
return Invalid;
|
||||
if (!check24(&input.data() [2], &hh))
|
||||
return Invalid;
|
||||
if (!check60(&input.data() [4], &mm))
|
||||
return Invalid;
|
||||
|
||||
|
||||
const QChar c = input[6];
|
||||
if (c < QLatin1Char('A') || c > QLatin1Char('Z'))
|
||||
return Invalid;
|
||||
if (c == QLatin1Char('J'))
|
||||
if (input[9] != QLatin1Char(' '))
|
||||
return Invalid;
|
||||
|
||||
const QChar c = input[10];
|
||||
if (c < QLatin1Char('A') || c > QLatin1Char('Z'))
|
||||
return Invalid;
|
||||
if (c == QLatin1Char('J'))
|
||||
{
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
const QString mon = input.mid(12, 3);
|
||||
int month = months().indexOf(mon);
|
||||
if (month < 0)
|
||||
{
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
for (int i = 16; i < 18; ++i)
|
||||
{
|
||||
if (!input[i].isDigit())
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
|
||||
const int day = input.left(2).toInt();
|
||||
const int year = input.mid(16, 2).toInt() + 2000;
|
||||
dt = QDateTime(QDate(year, month + 1, day), QTime(hh, mm, ss), QTimeZone::utc());
|
||||
if (!dt.isValid())
|
||||
{
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
dt = dt.addSecs(-timezone2Hours(c.toLatin1()) * 3600);
|
||||
|
||||
|
||||
return Acceptable;
|
||||
}
|
||||
|
||||
static DTGValidation validate7(const QString &input, QDateTime &dt)
|
||||
{
|
||||
|
||||
return Invalid;
|
||||
int hh, mm;
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
if (!input[i].isDigit())
|
||||
return Invalid;
|
||||
}
|
||||
if (!check31(&input.data()[0]))
|
||||
return Invalid;
|
||||
if (!check24(&input.data()[2], &hh))
|
||||
return Invalid;
|
||||
if (!check60(&input.data()[4], &mm))
|
||||
return Invalid;
|
||||
|
||||
|
||||
const QChar c = input[6];
|
||||
if (c < QLatin1Char('A') || c > QLatin1Char('Z'))
|
||||
return Invalid;
|
||||
if (c == QLatin1Char('J'))
|
||||
{
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
|
||||
const int day = input.left(2).toInt();
|
||||
const QDate curDate = QDate::currentDate();
|
||||
dt = QDateTime(QDate(curDate.year(), curDate.month(), day), QTime(hh, mm), QTimeZone::utc());
|
||||
if (!dt.isValid())
|
||||
{
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
dt = dt.addSecs(-timezone2Hours(c.toLatin1()) * 3600);
|
||||
|
||||
|
||||
return Acceptable;
|
||||
}
|
||||
|
||||
|
||||
const int day = input.left(2).toInt();
|
||||
const QDate curDate = QDate::currentDate();
|
||||
dt = QDateTime(QDate(curDate.year(), curDate.month(), day), QTime(hh, mm), QTimeZone::utc());
|
||||
if (!dt.isValid())
|
||||
QDateTime fromDTGString(const QString &str, bool *bOk)
|
||||
{
|
||||
|
||||
if (bOk)
|
||||
*bOk = false;
|
||||
|
||||
QDateTime dt;
|
||||
if (str.length() == 7)
|
||||
{
|
||||
DTGValidation state = validate7(str, dt);
|
||||
if (state == Acceptable && bOk)
|
||||
*bOk = true;
|
||||
}
|
||||
else if (str.length() == 18)
|
||||
{
|
||||
DTGValidation state = validate18(str, dt);
|
||||
if (state == Acceptable && bOk)
|
||||
*bOk = true;
|
||||
}
|
||||
return dt;
|
||||
}
|
||||
|
||||
DTGValidation validateString(const QString &str, QDateTime &dt)
|
||||
{
|
||||
const int len = str.length();
|
||||
if (len == 7 || len == 18)
|
||||
{
|
||||
|
||||
if (len == 18 || (str[2] == QLatin1Char(' ')))
|
||||
return validate18(str, dt);
|
||||
return validate7(str, dt);
|
||||
}
|
||||
return Invalid;
|
||||
}
|
||||
dt = dt.addSecs(-timezone2Hours(c.toLatin1()) * 3600);
|
||||
|
||||
|
||||
return Acceptable;
|
||||
QStringList months()
|
||||
{
|
||||
return {QLatin1String("jan"),
|
||||
QLatin1String("feb"),
|
||||
QLatin1String("mar"),
|
||||
QLatin1String("apr"),
|
||||
QLatin1String("may"),
|
||||
QLatin1String("jun"),
|
||||
QLatin1String("jul"),
|
||||
QLatin1String("aug"),
|
||||
QLatin1String("sep"),
|
||||
QLatin1String("oct"),
|
||||
QLatin1String("nov"),
|
||||
QLatin1String("dec")};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QDateTime fromDTGString(const QString &str, bool *bOk)
|
||||
{
|
||||
if (bOk)
|
||||
*bOk = false;
|
||||
|
||||
QDateTime dt;
|
||||
if (str.length() == 7)
|
||||
{
|
||||
DTGValidation state = validate7(str, dt);
|
||||
if (state == Acceptable && bOk)
|
||||
*bOk = true;
|
||||
}
|
||||
else if (str.length() == 18)
|
||||
{
|
||||
DTGValidation state = validate18(str, dt);
|
||||
if (state == Acceptable && bOk)
|
||||
*bOk = true;
|
||||
}
|
||||
return dt;
|
||||
}
|
||||
|
||||
DTGValidation validateString(const QString &str, QDateTime &dt)
|
||||
{
|
||||
const int len = str.length();
|
||||
if (len == 7 || len == 18)
|
||||
{
|
||||
|
||||
if (len == 18 || (str[2] == QLatin1Char(' ')))
|
||||
return validate18(str, dt);
|
||||
return validate7(str, dt);
|
||||
}
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
QStringList months()
|
||||
{
|
||||
return {
|
||||
QLatin1String("jan"), QLatin1String("feb"), QLatin1String("mar"),
|
||||
QLatin1String("apr"), QLatin1String("may"), QLatin1String("jun"),
|
||||
QLatin1String("jul"), QLatin1String("aug"), QLatin1String("sep"),
|
||||
QLatin1String("oct"), QLatin1String("nov"), QLatin1String("dec")
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+37
-45
@@ -10,78 +10,70 @@ namespace DTG
|
||||
{
|
||||
|
||||
|
||||
|
||||
enum DateTimeType
|
||||
{
|
||||
DTG = 1,
|
||||
DDMMYYYY_HHMMSS_Z = 2,
|
||||
DDMMYYYY_Z_HHMMSS = 4
|
||||
};
|
||||
enum DateTimeType
|
||||
{
|
||||
DTG = 1,
|
||||
DDMMYYYY_HHMMSS_Z = 2,
|
||||
DDMMYYYY_Z_HHMMSS = 4
|
||||
};
|
||||
|
||||
|
||||
enum DisplayFormat
|
||||
{
|
||||
Short,
|
||||
Long,
|
||||
TurboLong,
|
||||
Default
|
||||
};
|
||||
|
||||
enum DTGValidation
|
||||
{
|
||||
Invalid,
|
||||
Intermediate,
|
||||
Acceptable
|
||||
};
|
||||
|
||||
|
||||
enum DisplayFormat
|
||||
{
|
||||
Short,
|
||||
Long,
|
||||
TurboLong,
|
||||
Default
|
||||
};
|
||||
|
||||
enum DTGValidation
|
||||
{
|
||||
Invalid,
|
||||
Intermediate,
|
||||
Acceptable
|
||||
};
|
||||
NGLTOOLS_EXPORT void setDateTimeType(DateTimeType dtType);
|
||||
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT void setDateTimeType(DateTimeType dtType);
|
||||
NGLTOOLS_EXPORT DateTimeType dateTimeType();
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT DateTimeType dateTimeType();
|
||||
NGLTOOLS_EXPORT void setDefaultDisplayFormat(DisplayFormat dtFormat);
|
||||
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT void setDefaultDisplayFormat(DisplayFormat dtFormat);
|
||||
NGLTOOLS_EXPORT DisplayFormat defaultDisplayFormat();
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT DisplayFormat defaultDisplayFormat();
|
||||
NGLTOOLS_EXPORT QString toString(const QDateTime &dt, DisplayFormat format = Default, DateTimeType = dateTimeType());
|
||||
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT QString toString(const QDateTime &dt, DisplayFormat format = Default, DateTimeType = dateTimeType());
|
||||
NGLTOOLS_EXPORT QString toStringMSec(qint64 msecSinceEpoch, DisplayFormat format = Default);
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT QString toStringMSec(qint64 msecSinceEpoch, DisplayFormat format = Default);
|
||||
NGLTOOLS_EXPORT QDateTime fromDTGString(const QString &str, bool *bOk = nullptr);
|
||||
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT QDateTime fromDTGString(const QString &str, bool *bOk = nullptr);
|
||||
NGLTOOLS_EXPORT DTGValidation validateString(const QString &str, QDateTime &dt);
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT DTGValidation validateString(const QString &str, QDateTime &dt);
|
||||
NGLTOOLS_EXPORT bool setTimezone(char tz, bool bUserDefinedZone);
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT char timezone();
|
||||
NGLTOOLS_EXPORT char timezoneUserDefined();
|
||||
NGLTOOLS_EXPORT char timezoneExerciseDefault();
|
||||
|
||||
NGLTOOLS_EXPORT bool setTimezone(char tz, bool bUserDefinedZone);
|
||||
NGLTOOLS_EXPORT bool isTimezoneValid(char tz);
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT char timezone();
|
||||
NGLTOOLS_EXPORT char timezoneUserDefined();
|
||||
NGLTOOLS_EXPORT char timezoneExerciseDefault();
|
||||
|
||||
NGLTOOLS_EXPORT bool isTimezoneValid(char tz);
|
||||
NGLTOOLS_EXPORT int timezone2Hours(char tz, bool *bOk = nullptr);
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT int timezone2Hours(char tz, bool *bOk = nullptr);
|
||||
NGLTOOLS_EXPORT int timezone2Secs(char tz, bool *bOk = nullptr);
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT int timezone2Secs(char tz, bool *bOk = nullptr);
|
||||
NGLTOOLS_EXPORT QStringList months();
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT QStringList months();
|
||||
|
||||
}
|
||||
}
|
||||
Executable → Regular
+13
-13
@@ -3,17 +3,17 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NGLTOOLS_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLTOOLS_EXPORT
|
||||
# else
|
||||
# ifdef WIN32
|
||||
# ifdef MAKE_NGLTOOLS_LIB
|
||||
# define NGLTOOLS_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define NGLTOOLS_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define NGLTOOLS_EXPORT __attribute__((visibility("default")))
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLTOOLS_EXPORT
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#ifdef MAKE_NGLTOOLS_LIB
|
||||
#define NGLTOOLS_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define NGLTOOLS_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define NGLTOOLS_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+212
-218
@@ -11,280 +11,274 @@
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
bool removeDirContentsRecursively(const QString &d, bool bAlsoDeleteBaseDir)
|
||||
{
|
||||
|
||||
QDir dir(d);
|
||||
if (!dir.exists())
|
||||
return false;
|
||||
|
||||
bool success = true;
|
||||
const QFileInfoList list = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries);
|
||||
for (const QFileInfo &fi : list)
|
||||
bool removeDirContentsRecursively(const QString &d, bool bAlsoDeleteBaseDir)
|
||||
{
|
||||
bool ret = false;
|
||||
if (fi.isDir())
|
||||
|
||||
QDir dir(d);
|
||||
if (!dir.exists())
|
||||
return false;
|
||||
|
||||
bool success = true;
|
||||
const QFileInfoList list = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries);
|
||||
for (const QFileInfo &fi : list)
|
||||
{
|
||||
ret = removeDirContentsRecursively(fi.absoluteFilePath());
|
||||
if (!ret)
|
||||
bool ret = false;
|
||||
if (fi.isDir())
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = dir.rmdir(fi.absoluteFilePath());
|
||||
ret = removeDirContentsRecursively(fi.absoluteFilePath());
|
||||
if (!ret)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = dir.rmdir(fi.absoluteFilePath());
|
||||
if (!ret)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (fi.isFile() || fi.isSymLink())
|
||||
{
|
||||
ret = dir.remove(fi.fileName());
|
||||
if (!ret)
|
||||
else if (fi.isFile() || fi.isSymLink())
|
||||
{
|
||||
|
||||
ret = dir.remove(fi.fileName());
|
||||
if (!ret)
|
||||
{
|
||||
}
|
||||
}
|
||||
success &= ret;
|
||||
}
|
||||
success &= ret;
|
||||
if (bAlsoDeleteBaseDir)
|
||||
success &= dir.rmpath(d);
|
||||
return success;
|
||||
}
|
||||
if (bAlsoDeleteBaseDir)
|
||||
success &= dir.rmpath(d);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool copyDirContentsToDir(const QString &source, const QString &destination, bool sourceIsRelative)
|
||||
{
|
||||
QString srcPath(source);
|
||||
|
||||
if (sourceIsRelative)
|
||||
bool copyDirContentsToDir(const QString &source, const QString &destination, bool sourceIsRelative)
|
||||
{
|
||||
QVector<QString> pathsToSearch = directories(FileType::ConfigFile);
|
||||
pathsToSearch.append(directories(FileType::ProjectConfigFile));
|
||||
for (const QString &basePath : std::as_const(pathsToSearch))
|
||||
QString srcPath(source);
|
||||
|
||||
if (sourceIsRelative)
|
||||
{
|
||||
QString absolutePath = basePath + QLatin1Char('/') + source;
|
||||
if (QDir(absolutePath).exists())
|
||||
QVector<QString> pathsToSearch = directories(FileType::ConfigFile);
|
||||
pathsToSearch.append(directories(FileType::ProjectConfigFile));
|
||||
for (const QString &basePath : std::as_const(pathsToSearch))
|
||||
{
|
||||
srcPath = absolutePath;
|
||||
break;
|
||||
QString absolutePath = basePath + QLatin1Char('/') + source;
|
||||
if (QDir(absolutePath).exists())
|
||||
{
|
||||
srcPath = absolutePath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (srcPath.isEmpty())
|
||||
return false;
|
||||
}
|
||||
if (srcPath.isEmpty())
|
||||
return false;
|
||||
}
|
||||
|
||||
QDir srcDir(srcPath);
|
||||
QDir dstDir(destination);
|
||||
QDir srcDir(srcPath);
|
||||
QDir dstDir(destination);
|
||||
|
||||
if (!dstDir.exists())
|
||||
{
|
||||
bool succ = dstDir.mkdir(destination);
|
||||
if (!succ)
|
||||
return false;
|
||||
}
|
||||
|
||||
const QFileInfoList dirList = srcDir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||
for (const QFileInfo &fi : dirList)
|
||||
{
|
||||
|
||||
if (!dstDir.exists())
|
||||
{
|
||||
bool succ = dstDir.mkdir(fi.fileName());
|
||||
bool succ = dstDir.mkdir(destination);
|
||||
if (!succ)
|
||||
return false;
|
||||
}
|
||||
bool succ = copyDirContentsToDir(fi.filePath(), dstDir.absolutePath() + QLatin1Char('/') + fi.fileName());
|
||||
if (!succ)
|
||||
return false;
|
||||
|
||||
const QFileInfoList dirList = srcDir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||
for (const QFileInfo &fi : dirList)
|
||||
{
|
||||
|
||||
if (!dstDir.exists())
|
||||
{
|
||||
bool succ = dstDir.mkdir(fi.fileName());
|
||||
if (!succ)
|
||||
return false;
|
||||
}
|
||||
bool succ = copyDirContentsToDir(fi.filePath(), dstDir.absolutePath() + QLatin1Char('/') + fi.fileName());
|
||||
if (!succ)
|
||||
return false;
|
||||
}
|
||||
|
||||
const QFileInfoList fileList = srcDir.entryInfoList(QDir::Files | QDir::Hidden);
|
||||
for (const QFileInfo &fi : fileList)
|
||||
{
|
||||
QString targetFileName = dstDir.absolutePath() + QLatin1Char('/') + fi.fileName();
|
||||
QFile targetFile(targetFileName);
|
||||
if (targetFile.exists())
|
||||
targetFile.remove();
|
||||
bool succ = QFile::copy(fi.absoluteFilePath(), targetFileName);
|
||||
if (!succ)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const QFileInfoList fileList = srcDir.entryInfoList(QDir::Files | QDir::Hidden);
|
||||
for (const QFileInfo &fi : fileList)
|
||||
qint64 getDirectorySize(const QString &dir)
|
||||
{
|
||||
QString targetFileName = dstDir.absolutePath() + QLatin1Char('/') + fi.fileName();
|
||||
QFile targetFile(targetFileName);
|
||||
if (targetFile.exists())
|
||||
targetFile.remove();
|
||||
bool succ = QFile::copy(fi.absoluteFilePath(), targetFileName);
|
||||
if (!succ)
|
||||
return false;
|
||||
QDir d(dir);
|
||||
qint64 ret = QFileInfo(dir).size();
|
||||
|
||||
const QFileInfoList dirList = d.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||
const QFileInfoList fileList = d.entryInfoList(QDir::Files | QDir::Hidden);
|
||||
|
||||
for (const QFileInfo &fi : dirList)
|
||||
ret += getDirectorySize(fi.absoluteFilePath());
|
||||
|
||||
for (const QFileInfo &fi : fileList)
|
||||
ret += fi.size();
|
||||
|
||||
return ret;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
qint64 getDirectorySize(const QString &dir)
|
||||
{
|
||||
QDir d(dir);
|
||||
qint64 ret = QFileInfo(dir).size();
|
||||
|
||||
const QFileInfoList dirList = d.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||
const QFileInfoList fileList = d.entryInfoList(QDir::Files | QDir::Hidden);
|
||||
|
||||
for (const QFileInfo &fi : dirList)
|
||||
ret += getDirectorySize(fi.absoluteFilePath());
|
||||
|
||||
for (const QFileInfo &fi : fileList)
|
||||
ret += fi.size();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool isAppInBuildBasePath()
|
||||
{
|
||||
bool ret = false;
|
||||
bool isAppInBuildBasePath()
|
||||
{
|
||||
bool ret = false;
|
||||
#ifdef BUILD_BASE_PATH
|
||||
const QString bbp(QString::fromLocal8Bit(BUILD_BASE_PATH));
|
||||
if (!bbp.isEmpty())
|
||||
ret = QCoreApplication::applicationDirPath().startsWith(bbp);
|
||||
const QString bbp(QString::fromLocal8Bit(BUILD_BASE_PATH));
|
||||
if (!bbp.isEmpty())
|
||||
ret = QCoreApplication::applicationDirPath().startsWith(bbp);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString projectConfigFileName()
|
||||
{
|
||||
return QLatin1String("lts-cc.conf");
|
||||
}
|
||||
QString projectConfigFileName()
|
||||
{
|
||||
return QLatin1String("lts-cc.conf");
|
||||
}
|
||||
|
||||
QString findProjectConfigFile()
|
||||
{
|
||||
return findFile(FileType::ProjectConfigFile, projectConfigFileName());
|
||||
}
|
||||
QString findProjectConfigFile()
|
||||
{
|
||||
return findFile(FileType::ProjectConfigFile, projectConfigFileName());
|
||||
}
|
||||
|
||||
static QString searchFileInDir(const QString &path, const QString &filename, bool bRecursive)
|
||||
{
|
||||
if (QFile::exists(path + QLatin1Char('/') + filename))
|
||||
return path + QLatin1Char('/') + filename;
|
||||
static QString searchFileInDir(const QString &path, const QString &filename, bool bRecursive)
|
||||
{
|
||||
if (QFile::exists(path + QLatin1Char('/') + filename))
|
||||
return path + QLatin1Char('/') + filename;
|
||||
|
||||
if (!bRecursive)
|
||||
if (!bRecursive)
|
||||
return QString();
|
||||
|
||||
const QDir d(path);
|
||||
const QStringList entryList = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
||||
for (const QString &entry : entryList)
|
||||
{
|
||||
const QString foundPath = searchFileInDir(path + QLatin1Char('/') + entry, filename, bRecursive);
|
||||
if (!foundPath.isEmpty())
|
||||
return foundPath;
|
||||
}
|
||||
return QString();
|
||||
|
||||
const QDir d(path);
|
||||
const QStringList entryList = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
||||
for (const QString &entry : entryList)
|
||||
{
|
||||
const QString foundPath = searchFileInDir(path + QLatin1Char('/') + entry, filename, bRecursive);
|
||||
if (!foundPath.isEmpty())
|
||||
return foundPath;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString findFile(FileType fileType, const QString &filename)
|
||||
{
|
||||
const QFileInfo fi(filename);
|
||||
if (fi.isAbsolute())
|
||||
return fi.exists() ? filename : QString();
|
||||
const bool bRecursive = (fileType == FileType::ConfigFile);
|
||||
const QVector<QString> pathsToSearch = directories(fileType);
|
||||
for (const QString &path : pathsToSearch)
|
||||
QString findFile(FileType fileType, const QString &filename)
|
||||
{
|
||||
const QString foundPath = searchFileInDir(path, filename, bRecursive);
|
||||
if (!foundPath.isEmpty())
|
||||
return foundPath;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QVector<QString> directories(FileType fileType)
|
||||
{
|
||||
QVector<QString> pathsToSearch;
|
||||
switch (fileType)
|
||||
{
|
||||
case FileType::ProjectConfigFile:
|
||||
{
|
||||
#ifdef BUILD_BASE_PATH
|
||||
const QString bbp(QString::fromLocal8Bit(BUILD_BASE_PATH));
|
||||
if (!bbp.isEmpty())
|
||||
const QFileInfo fi(filename);
|
||||
if (fi.isAbsolute())
|
||||
return fi.exists() ? filename : QString();
|
||||
const bool bRecursive = (fileType == FileType::ConfigFile);
|
||||
const QVector<QString> pathsToSearch = directories(fileType);
|
||||
for (const QString &path : pathsToSearch)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (QCoreApplication::applicationDirPath().startsWith(bbp))
|
||||
pathsToSearch += bbp;
|
||||
const QString foundPath = searchFileInDir(path, filename, bRecursive);
|
||||
if (!foundPath.isEmpty())
|
||||
return foundPath;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QVector<QString> directories(FileType fileType)
|
||||
{
|
||||
QVector<QString> pathsToSearch;
|
||||
switch (fileType)
|
||||
{
|
||||
case FileType::ProjectConfigFile:
|
||||
{
|
||||
#ifdef BUILD_BASE_PATH
|
||||
const QString bbp(QString::fromLocal8Bit(BUILD_BASE_PATH));
|
||||
if (!bbp.isEmpty())
|
||||
{
|
||||
|
||||
|
||||
if (QCoreApplication::applicationDirPath().startsWith(bbp))
|
||||
pathsToSearch += bbp;
|
||||
}
|
||||
#endif
|
||||
pathsToSearch += QDir::homePath();
|
||||
pathsToSearch += QDir::homePath();
|
||||
#ifdef Q_OS_UNIX
|
||||
pathsToSearch += QLatin1String("/etc");
|
||||
pathsToSearch += QLatin1String("/etc");
|
||||
#else
|
||||
pathsToSearch += QStringLiteral("C:/Rheinmetall/Lts/");
|
||||
pathsToSearch += QCoreApplication::applicationDirPath();
|
||||
pathsToSearch += QStringLiteral("C:/Rheinmetall/Lts/");
|
||||
pathsToSearch += QCoreApplication::applicationDirPath();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case FileType::ConfigFile:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case FileType::ConfigFile:
|
||||
{
|
||||
#ifdef BUILD_BASE_PATH
|
||||
const QString bbp(QString::fromLocal8Bit(BUILD_BASE_PATH));
|
||||
if (!bbp.isEmpty())
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (QCoreApplication::applicationDirPath().startsWith(bbp))
|
||||
pathsToSearch += bbp + QLatin1String("/share/Lts");
|
||||
}
|
||||
const QString bbp(QString::fromLocal8Bit(BUILD_BASE_PATH));
|
||||
if (!bbp.isEmpty())
|
||||
{
|
||||
|
||||
|
||||
if (QCoreApplication::applicationDirPath().startsWith(bbp))
|
||||
pathsToSearch += bbp + QLatin1String("/share/Lts");
|
||||
}
|
||||
#endif
|
||||
pathsToSearch += QCoreApplication::applicationDirPath() + QLatin1String("/share/Lts");
|
||||
pathsToSearch += QCoreApplication::applicationDirPath() + QLatin1String("/../share/Lts");
|
||||
pathsToSearch += QDir::homePath() + QLatin1String("/share/Lts");
|
||||
pathsToSearch += QCoreApplication::applicationDirPath() + QLatin1String("/share/Lts");
|
||||
pathsToSearch += QCoreApplication::applicationDirPath() + QLatin1String("/../share/Lts");
|
||||
pathsToSearch += QDir::homePath() + QLatin1String("/share/Lts");
|
||||
#ifdef INSTALL_PREFIX
|
||||
pathsToSearch += QString::fromLocal8Bit(INSTALL_PREFIX) + QLatin1String("/share/Lts");
|
||||
pathsToSearch += QString::fromLocal8Bit(INSTALL_PREFIX) + QLatin1String("/share/Lts");
|
||||
#endif
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pathsToSearch;
|
||||
}
|
||||
}
|
||||
return pathsToSearch;
|
||||
}
|
||||
QString findServiceXmlFile(const QString &serviceShortName)
|
||||
{
|
||||
return findFile(FileType::ConfigFile, serviceShortName + QLatin1String(".xml"));
|
||||
}
|
||||
|
||||
QString directory(FileType fileType, const QString &subdir)
|
||||
{
|
||||
const QVector<QString> pathsToSearch = directories(fileType);
|
||||
QFileInfo fi;
|
||||
for (const QString &path : pathsToSearch)
|
||||
QString findServiceXmlFile(const QString &serviceShortName)
|
||||
{
|
||||
fi.setFile(path + QLatin1Char('/') + subdir);
|
||||
if (fi.isDir() && fi.exists() && fi.isReadable())
|
||||
return fi.absoluteFilePath() + QLatin1Char('/');
|
||||
return findFile(FileType::ConfigFile, serviceShortName + QLatin1String(".xml"));
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString postgresExecutablePath(const QString &psqlProgram, QString &errStr)
|
||||
{
|
||||
errStr.clear();
|
||||
QString directory(FileType fileType, const QString &subdir)
|
||||
{
|
||||
const QVector<QString> pathsToSearch = directories(fileType);
|
||||
QFileInfo fi;
|
||||
for (const QString &path : pathsToSearch)
|
||||
{
|
||||
fi.setFile(path + QLatin1Char('/') + subdir);
|
||||
if (fi.isDir() && fi.exists() && fi.isReadable())
|
||||
return fi.absoluteFilePath() + QLatin1Char('/');
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString postgresExecutablePath(const QString &psqlProgram, QString &errStr)
|
||||
{
|
||||
errStr.clear();
|
||||
#ifdef Q_OS_LINUX
|
||||
return QStringLiteral("/usr/bin/") + psqlProgram;
|
||||
return QStringLiteral("/usr/bin/") + psqlProgram;
|
||||
#else
|
||||
static QString s_postgresBinariesPath;
|
||||
if (s_postgresBinariesPath.isEmpty())
|
||||
{
|
||||
QSettings s(QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\PostgreSQL\\Installations"), QSettings::NativeFormat);
|
||||
const QStringList installations = s.childGroups();
|
||||
if (installations.isEmpty())
|
||||
static QString s_postgresBinariesPath;
|
||||
if (s_postgresBinariesPath.isEmpty())
|
||||
{
|
||||
errStr = QStringLiteral("Could not find a valid PostgreSQL windows installation...");
|
||||
return psqlProgram;
|
||||
QSettings s(QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\PostgreSQL\\Installations"), QSettings::NativeFormat);
|
||||
const QStringList installations = s.childGroups();
|
||||
if (installations.isEmpty())
|
||||
{
|
||||
errStr = QStringLiteral("Could not find a valid PostgreSQL windows installation...");
|
||||
return psqlProgram;
|
||||
}
|
||||
if (installations.size() > 1)
|
||||
errStr = QStringLiteral("More than one PostgreSQL windows installation found - using the first one: %1").arg(installations.first());
|
||||
s.beginGroup(installations.first());
|
||||
const QString baseDir = s.value(QStringLiteral("Base Directory")).toString();
|
||||
if (baseDir.isEmpty() || !QDir(baseDir).exists())
|
||||
{
|
||||
errStr = QStringLiteral("Could not find a valid PostgreSQL windows installation... - Base Directory is empty or does not exist (%1)").arg(baseDir);
|
||||
return psqlProgram;
|
||||
}
|
||||
s_postgresBinariesPath = baseDir + QStringLiteral("/bin/");
|
||||
}
|
||||
if (installations.size() > 1)
|
||||
errStr = QStringLiteral("More than one PostgreSQL windows installation found - using the first one: %1").arg(installations.first());
|
||||
s.beginGroup(installations.first());
|
||||
const QString baseDir = s.value(QStringLiteral("Base Directory")).toString();
|
||||
if (baseDir.isEmpty() || !QDir(baseDir).exists())
|
||||
{
|
||||
errStr = QStringLiteral("Could not find a valid PostgreSQL windows installation... - Base Directory is empty or does not exist (%1)").arg(baseDir);
|
||||
return psqlProgram;
|
||||
}
|
||||
s_postgresBinariesPath = baseDir + QStringLiteral("/bin/");
|
||||
}
|
||||
return s_postgresBinariesPath + psqlProgram + QStringLiteral(".exe");
|
||||
return s_postgresBinariesPath + psqlProgram + QStringLiteral(".exe");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable → Regular
+7
-7
@@ -10,10 +10,10 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
NGLTOOLS_EXPORT bool removeDirContentsRecursively(const QString &d, bool bAlsoDeleteBaseDir = false);
|
||||
NGLTOOLS_EXPORT bool copyDirContentsToDir(const QString &source, const QString &destination, bool sourceIsRelative = false);
|
||||
NGLTOOLS_EXPORT bool removeDirContentsRecursively(const QString &d, bool bAlsoDeleteBaseDir = false);
|
||||
NGLTOOLS_EXPORT bool copyDirContentsToDir(const QString &source, const QString &destination, bool sourceIsRelative = false);
|
||||
NGLTOOLS_EXPORT qint64 getDirectorySize(const QString &dir);
|
||||
|
||||
|
||||
|
||||
enum class FileType
|
||||
{
|
||||
@@ -25,14 +25,14 @@ namespace NGL
|
||||
NGLTOOLS_EXPORT QString projectConfigFileName();
|
||||
NGLTOOLS_EXPORT QString findProjectConfigFile();
|
||||
NGLTOOLS_EXPORT QString findFile(FileType fileType, const QString &filename);
|
||||
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT QString findServiceXmlFile(const QString &serviceShortName);
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT QVector<QString> directories(FileType fileType);
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT QString directory(FileType fileType, const QString &subdir);
|
||||
|
||||
|
||||
|
||||
NGLTOOLS_EXPORT QString postgresExecutablePath(const QString &psqlProgram, QString &errStr);
|
||||
}
|
||||
Executable → Regular
+1
-1
@@ -13,7 +13,7 @@ void NGLHelpEvent::sendHelpEvent(const QString &helpContext)
|
||||
|
||||
QEvent::Type NGLHelpEvent::helpEventId()
|
||||
{
|
||||
if(sHelpEventId < 0)
|
||||
if (sHelpEventId < 0)
|
||||
sHelpEventId = (QEvent::Type)(QEvent::registerEventType());
|
||||
return sHelpEventId;
|
||||
}
|
||||
Executable → Regular
+7
-10
@@ -7,24 +7,21 @@
|
||||
#include "ngltools_export.h"
|
||||
|
||||
|
||||
|
||||
class NGLTOOLS_EXPORT NGLHelpEvent : public QEvent
|
||||
{
|
||||
protected:
|
||||
|
||||
|
||||
explicit NGLHelpEvent(const QString &helpContext)
|
||||
: QEvent(helpEventId())
|
||||
, mHelpContext(helpContext)
|
||||
{}
|
||||
public:
|
||||
|
||||
: QEvent(helpEventId())
|
||||
, mHelpContext(helpContext)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
QString helpContext() const { return mHelpContext; }
|
||||
|
||||
|
||||
|
||||
static void sendHelpEvent(const QString &helpContext);
|
||||
|
||||
|
||||
|
||||
static QEvent::Type helpEventId();
|
||||
|
||||
|
||||
@@ -6,18 +6,18 @@
|
||||
|
||||
class NGLToolsQtSmokeTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void testDTG()
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTimeUtc();
|
||||
QString s = DTG::toString(now, DTG::Default, DTG::DTG);
|
||||
QVERIFY(!s.isEmpty());
|
||||
bool ok = false;
|
||||
QDateTime parsed = DTG::fromDTGString(s, &ok);
|
||||
QVERIFY(ok);
|
||||
QVERIFY(parsed.isValid());
|
||||
}
|
||||
void testDTG()
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTimeUtc();
|
||||
QString s = DTG::toString(now, DTG::Default, DTG::DTG);
|
||||
QVERIFY(!s.isEmpty());
|
||||
bool ok = false;
|
||||
QDateTime parsed = DTG::fromDTGString(s, &ok);
|
||||
QVERIFY(ok);
|
||||
QVERIFY(parsed.isValid());
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(NGLToolsQtSmokeTest)
|
||||
|
||||
Executable → Regular
+164
-175
@@ -19,212 +19,201 @@
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
struct TranslationData
|
||||
{
|
||||
QByteArray isoCode;
|
||||
QString qmPrefix;
|
||||
QTranslator qtTranslator;
|
||||
QTranslator kdReportsTranslator;
|
||||
QTranslator ltsTranslator;
|
||||
Translator dynamicTranslator;
|
||||
struct TranslationData
|
||||
{
|
||||
QByteArray isoCode;
|
||||
QString qmPrefix;
|
||||
QTranslator qtTranslator;
|
||||
QTranslator kdReportsTranslator;
|
||||
QTranslator ltsTranslator;
|
||||
Translator dynamicTranslator;
|
||||
|
||||
TranslationData()
|
||||
{
|
||||
QCoreApplication::installTranslator(&qtTranslator);
|
||||
QCoreApplication::installTranslator(&kdReportsTranslator);
|
||||
QCoreApplication::installTranslator(<sTranslator);
|
||||
QCoreApplication::installTranslator(&dynamicTranslator);
|
||||
}
|
||||
~TranslationData()
|
||||
{
|
||||
if (qApp)
|
||||
TranslationData()
|
||||
{
|
||||
QCoreApplication::removeTranslator(&qtTranslator);
|
||||
QCoreApplication::removeTranslator(&kdReportsTranslator);
|
||||
QCoreApplication::removeTranslator(<sTranslator);
|
||||
QCoreApplication::removeTranslator(&dynamicTranslator);
|
||||
QCoreApplication::installTranslator(&qtTranslator);
|
||||
QCoreApplication::installTranslator(&kdReportsTranslator);
|
||||
QCoreApplication::installTranslator(<sTranslator);
|
||||
QCoreApplication::installTranslator(&dynamicTranslator);
|
||||
}
|
||||
~TranslationData()
|
||||
{
|
||||
if (qApp)
|
||||
{
|
||||
QCoreApplication::removeTranslator(&qtTranslator);
|
||||
QCoreApplication::removeTranslator(&kdReportsTranslator);
|
||||
QCoreApplication::removeTranslator(<sTranslator);
|
||||
QCoreApplication::removeTranslator(&dynamicTranslator);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(TranslationData, s_translationData)
|
||||
|
||||
|
||||
Translator::Translator(QObject *parent)
|
||||
: QTranslator(parent)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(TranslationData, s_translationData)
|
||||
|
||||
|
||||
Translator::Translator(QObject *parent)
|
||||
: QTranslator(parent)
|
||||
{}
|
||||
void Translator::setTranslationCatalog(const TranslationCatalog &catalog)
|
||||
{
|
||||
m_catalog = catalog;
|
||||
m_md5Sum.clear();
|
||||
isoCodeChanged(s_translationData()->isoCode);
|
||||
}
|
||||
|
||||
bool Translator::setTranslationDataJson(const QByteArray &jsonData, const QByteArray &md5Sum, bool bCompressed)
|
||||
{
|
||||
if (m_md5Sum == md5Sum)
|
||||
return true;
|
||||
|
||||
void Translator::setTranslationCatalog(const TranslationCatalog &catalog)
|
||||
{
|
||||
m_catalog = catalog;
|
||||
m_md5Sum.clear();
|
||||
isoCodeChanged(s_translationData()->isoCode);
|
||||
}
|
||||
// Use fromJson; fromBinaryData is not available in this Qt build
|
||||
const QByteArray jsonRaw = bCompressed ? qUncompress(jsonData) : jsonData;
|
||||
const QJsonObject jObj = QJsonDocument::fromJson(jsonRaw).object();
|
||||
const QString translationKey(QStringLiteral("translations"));
|
||||
if (jObj.empty() || !jObj.contains(translationKey) || !jObj.value(translationKey).isArray())
|
||||
return false;
|
||||
|
||||
bool Translator::setTranslationDataJson(const QByteArray &jsonData, const QByteArray &md5Sum, bool bCompressed)
|
||||
{
|
||||
if (m_md5Sum == md5Sum)
|
||||
return true;
|
||||
const QJsonArray arr = jObj[translationKey].toArray();
|
||||
|
||||
m_catalog.clear();
|
||||
m_catalog.reserve(arr.size());
|
||||
TranslationEntry te;
|
||||
for (const QJsonValue &element : arr)
|
||||
{
|
||||
const QJsonObject obj = element.toObject();
|
||||
|
||||
te.isoCode = obj.value(QStringLiteral("isoCode")).toString().toUtf8();
|
||||
te.context = obj.value(QStringLiteral("context")).toString().toUtf8();
|
||||
te.key = obj.value(QStringLiteral("key")).toString().toUtf8();
|
||||
te.disambiguation = obj.value(QStringLiteral("disambiguation")).toString().toUtf8();
|
||||
te.translation = obj.value(QStringLiteral("translation")).toString();
|
||||
|
||||
m_catalog += te;
|
||||
}
|
||||
|
||||
m_md5Sum = md5Sum;
|
||||
isoCodeChanged(s_translationData()->isoCode);
|
||||
|
||||
// Use fromJson; fromBinaryData is not available in this Qt build
|
||||
const QByteArray jsonRaw = bCompressed ? qUncompress(jsonData) : jsonData;
|
||||
const QJsonObject jObj = QJsonDocument::fromJson(jsonRaw).object();
|
||||
const QString translationKey(QStringLiteral("translations"));
|
||||
if (jObj.empty() ||
|
||||
!jObj.contains(translationKey) ||
|
||||
!jObj.value(translationKey).isArray())
|
||||
return false;
|
||||
|
||||
const QJsonArray arr = jObj[translationKey].toArray();
|
||||
|
||||
m_catalog.clear();
|
||||
m_catalog.reserve(arr.size());
|
||||
TranslationEntry te;
|
||||
for (const QJsonValue &element : arr)
|
||||
{
|
||||
const QJsonObject obj = element.toObject();
|
||||
|
||||
te.isoCode = obj.value(QStringLiteral("isoCode")).toString().toUtf8();
|
||||
te.context = obj.value(QStringLiteral("context")).toString().toUtf8();
|
||||
te.key = obj.value(QStringLiteral("key")).toString().toUtf8();
|
||||
te.disambiguation = obj.value(QStringLiteral("disambiguation")).toString().toUtf8();
|
||||
te.translation = obj.value(QStringLiteral("translation")).toString();
|
||||
|
||||
m_catalog += te;
|
||||
}
|
||||
|
||||
m_md5Sum = md5Sum;
|
||||
isoCodeChanged(s_translationData()->isoCode);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString Translator::translate(const char *context,
|
||||
const char *sourceText,
|
||||
const char *disambiguation,
|
||||
int n) const
|
||||
{
|
||||
|
||||
if (n != -1)
|
||||
return QString();
|
||||
|
||||
const auto itCtx = m_translationLookup.find(QByteArray::fromRawData(context, strlen(context)));
|
||||
if (itCtx == m_translationLookup.end())
|
||||
return QString();
|
||||
const auto itKey = itCtx.value().find(QByteArray::fromRawData(sourceText, strlen(sourceText)));
|
||||
if (itKey == itCtx.value().end())
|
||||
return QString();
|
||||
const auto itDis = itKey.value().find(disambiguation ? QByteArray::fromRawData(disambiguation, strlen(disambiguation)) : QByteArray());
|
||||
if (itDis == itKey.value().end())
|
||||
return QString();
|
||||
return itDis.value();
|
||||
}
|
||||
|
||||
|
||||
void Translator::isoCodeChanged(const QByteArray &isoCode)
|
||||
{
|
||||
m_translationLookup.clear();
|
||||
for (const TranslationEntry &te : std::as_const(m_catalog))
|
||||
QString Translator::translate(const char *context, const char *sourceText, const char *disambiguation, int n) const
|
||||
{
|
||||
if (te.isoCode != isoCode)
|
||||
continue;
|
||||
m_translationLookup[te.context][te.key][te.disambiguation] = te.translation;
|
||||
|
||||
if (n != -1)
|
||||
return QString();
|
||||
|
||||
const auto itCtx = m_translationLookup.find(QByteArray::fromRawData(context, strlen(context)));
|
||||
if (itCtx == m_translationLookup.end())
|
||||
return QString();
|
||||
const auto itKey = itCtx.value().find(QByteArray::fromRawData(sourceText, strlen(sourceText)));
|
||||
if (itKey == itCtx.value().end())
|
||||
return QString();
|
||||
const auto itDis = itKey.value().find(disambiguation ? QByteArray::fromRawData(disambiguation, strlen(disambiguation)) : QByteArray());
|
||||
if (itDis == itKey.value().end())
|
||||
return QString();
|
||||
return itDis.value();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void setTranslationCatalog(const TranslationCatalog &catalog)
|
||||
{
|
||||
s_translationData()->dynamicTranslator.setTranslationCatalog(catalog);
|
||||
}
|
||||
|
||||
|
||||
bool setTranslationDataJson(const QByteArray &jsonData, const QByteArray &md5Sum, bool bCompressed)
|
||||
{
|
||||
return s_translationData()->dynamicTranslator.setTranslationDataJson(jsonData, md5Sum, bCompressed);
|
||||
}
|
||||
|
||||
|
||||
bool setTranslationLocale(const QByteArray &isoCode, const QString &qmPrefix)
|
||||
{
|
||||
|
||||
if (s_translationData()->isoCode == isoCode &&
|
||||
s_translationData()->qmPrefix == qmPrefix)
|
||||
return true;
|
||||
|
||||
s_translationData()->isoCode = isoCode;
|
||||
s_translationData()->qmPrefix = qmPrefix;
|
||||
|
||||
const QString relTranslationPath = QLatin1Char('/') + QString::fromLatin1(isoCode) + QLatin1Char('/');
|
||||
const QStringList possiblePaths = { QCoreApplication::applicationDirPath() + QStringLiteral("/translations/"),
|
||||
QCoreApplication::applicationDirPath() + QStringLiteral("/../translations/"),
|
||||
QDir::homePath() + QStringLiteral("/translations/")
|
||||
};
|
||||
const QString qm(QStringLiteral(".qm"));
|
||||
|
||||
QString ltsQmPath;
|
||||
for (const QString &path : possiblePaths)
|
||||
void Translator::isoCodeChanged(const QByteArray &isoCode)
|
||||
{
|
||||
const QString absPath = path + relTranslationPath;
|
||||
if (!QDir(absPath).exists())
|
||||
continue;
|
||||
if (QTranslator().load(qmPrefix + qm, absPath))
|
||||
m_translationLookup.clear();
|
||||
for (const TranslationEntry &te : std::as_const(m_catalog))
|
||||
{
|
||||
ltsQmPath = absPath + qmPrefix + qm;
|
||||
break;
|
||||
if (te.isoCode != isoCode)
|
||||
continue;
|
||||
m_translationLookup[te.context][te.key][te.disambiguation] = te.translation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString kdReportsQmPath;
|
||||
const QString kdReportsPrefix(QStringLiteral("kdreports"));
|
||||
for (const QString &path : possiblePaths)
|
||||
|
||||
void setTranslationCatalog(const TranslationCatalog &catalog)
|
||||
{
|
||||
const QString absPath = path + relTranslationPath;
|
||||
if (!QDir(absPath).exists())
|
||||
continue;
|
||||
if (QTranslator().load(kdReportsPrefix + qm, absPath))
|
||||
s_translationData()->dynamicTranslator.setTranslationCatalog(catalog);
|
||||
}
|
||||
|
||||
|
||||
bool setTranslationDataJson(const QByteArray &jsonData, const QByteArray &md5Sum, bool bCompressed)
|
||||
{
|
||||
return s_translationData()->dynamicTranslator.setTranslationDataJson(jsonData, md5Sum, bCompressed);
|
||||
}
|
||||
|
||||
|
||||
bool setTranslationLocale(const QByteArray &isoCode, const QString &qmPrefix)
|
||||
{
|
||||
|
||||
if (s_translationData()->isoCode == isoCode && s_translationData()->qmPrefix == qmPrefix)
|
||||
return true;
|
||||
|
||||
s_translationData()->isoCode = isoCode;
|
||||
s_translationData()->qmPrefix = qmPrefix;
|
||||
|
||||
const QString relTranslationPath = QLatin1Char('/') + QString::fromLatin1(isoCode) + QLatin1Char('/');
|
||||
const QStringList possiblePaths = {QCoreApplication::applicationDirPath() + QStringLiteral("/translations/"),
|
||||
QCoreApplication::applicationDirPath() + QStringLiteral("/../translations/"),
|
||||
QDir::homePath() + QStringLiteral("/translations/")};
|
||||
const QString qm(QStringLiteral(".qm"));
|
||||
|
||||
QString ltsQmPath;
|
||||
for (const QString &path : possiblePaths)
|
||||
{
|
||||
kdReportsQmPath = absPath + kdReportsPrefix + qm;
|
||||
break;
|
||||
const QString absPath = path + relTranslationPath;
|
||||
if (!QDir(absPath).exists())
|
||||
continue;
|
||||
if (QTranslator().load(qmPrefix + qm, absPath))
|
||||
{
|
||||
ltsQmPath = absPath + qmPrefix + qm;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QStringList isoCodeList(QString::fromLatin1(isoCode).split(QLatin1Char('_')));
|
||||
if (isoCodeList.count() == 2)
|
||||
{
|
||||
if (!s_translationData->qtTranslator.load(QLatin1String("qt_") + isoCodeList.at(0),
|
||||
QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
|
||||
|
||||
QString kdReportsQmPath;
|
||||
const QString kdReportsPrefix(QStringLiteral("kdreports"));
|
||||
for (const QString &path : possiblePaths)
|
||||
{
|
||||
qWarning("qtTranslator.load failed for %s", qPrintable(isoCodeList.at(0)));
|
||||
const QString absPath = path + relTranslationPath;
|
||||
if (!QDir(absPath).exists())
|
||||
continue;
|
||||
if (QTranslator().load(kdReportsPrefix + qm, absPath))
|
||||
{
|
||||
kdReportsQmPath = absPath + kdReportsPrefix + qm;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QStringList isoCodeList(QString::fromLatin1(isoCode).split(QLatin1Char('_')));
|
||||
if (isoCodeList.count() == 2)
|
||||
{
|
||||
if (!s_translationData->qtTranslator.load(QLatin1String("qt_") + isoCodeList.at(0), QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
|
||||
{
|
||||
qWarning("qtTranslator.load failed for %s", qPrintable(isoCodeList.at(0)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
qWarning() << "translation iso code not compatible with qt translations";
|
||||
}
|
||||
|
||||
if (!s_translationData->kdReportsTranslator.load(kdReportsQmPath))
|
||||
qWarning("kdReportsTranslator.load failed: %s", qPrintable(kdReportsQmPath));
|
||||
if (!s_translationData->ltsTranslator.load(ltsQmPath))
|
||||
qWarning("ltsTranslator.load failed: %s", qPrintable(ltsQmPath));
|
||||
s_translationData->dynamicTranslator.isoCodeChanged(isoCode);
|
||||
|
||||
return !s_translationData->ltsTranslator.isEmpty();
|
||||
}
|
||||
else
|
||||
|
||||
|
||||
QByteArray translationLocale()
|
||||
{
|
||||
|
||||
qWarning() << "translation iso code not compatible with qt translations";
|
||||
return s_translationData()->isoCode;
|
||||
}
|
||||
|
||||
if (!s_translationData->kdReportsTranslator.load(kdReportsQmPath))
|
||||
qWarning("kdReportsTranslator.load failed: %s", qPrintable(kdReportsQmPath));
|
||||
if (!s_translationData->ltsTranslator.load(ltsQmPath))
|
||||
qWarning("ltsTranslator.load failed: %s", qPrintable(ltsQmPath));
|
||||
s_translationData->dynamicTranslator.isoCodeChanged(isoCode);
|
||||
|
||||
return !s_translationData->ltsTranslator.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
QByteArray translationLocale()
|
||||
{
|
||||
return s_translationData()->isoCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Executable → Regular
+14
-18
@@ -11,30 +11,26 @@
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
struct TranslationEntry
|
||||
{
|
||||
QByteArray isoCode;
|
||||
QByteArray context;
|
||||
QByteArray key;
|
||||
QByteArray disambiguation;
|
||||
QString translation;
|
||||
};
|
||||
using TranslationCatalog = QVector<TranslationEntry>;
|
||||
struct TranslationEntry
|
||||
{
|
||||
QByteArray isoCode;
|
||||
QByteArray context;
|
||||
QByteArray key;
|
||||
QByteArray disambiguation;
|
||||
QString translation;
|
||||
};
|
||||
using TranslationCatalog = QVector<TranslationEntry>;
|
||||
|
||||
|
||||
|
||||
NGLTRANSLATOR_EXPORT void setTranslationCatalog(const TranslationCatalog &catalog);
|
||||
NGLTRANSLATOR_EXPORT void setTranslationCatalog(const TranslationCatalog &catalog);
|
||||
|
||||
|
||||
|
||||
NGLTRANSLATOR_EXPORT bool setTranslationDataJson(const QByteArray &jsonData, const QByteArray &md5Sum, bool bCompressed);
|
||||
NGLTRANSLATOR_EXPORT bool setTranslationDataJson(const QByteArray &jsonData, const QByteArray &md5Sum, bool bCompressed);
|
||||
|
||||
|
||||
|
||||
NGLTRANSLATOR_EXPORT bool setTranslationLocale(const QByteArray &isoCode, const QString &qmPrefix = QStringLiteral("tds"));
|
||||
NGLTRANSLATOR_EXPORT bool setTranslationLocale(const QByteArray &isoCode, const QString &qmPrefix = QStringLiteral("tds"));
|
||||
|
||||
|
||||
NGLTRANSLATOR_EXPORT QByteArray translationLocale();
|
||||
|
||||
NGLTRANSLATOR_EXPORT QByteArray translationLocale();
|
||||
|
||||
}
|
||||
}
|
||||
Executable → Regular
+13
-13
@@ -3,17 +3,17 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NGLTRANSLATOR_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLTRANSLATOR_EXPORT
|
||||
# else
|
||||
# ifdef WIN32
|
||||
# ifdef MAKE_NGLTRANSLATOR_LIB
|
||||
# define NGLTRANSLATOR_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define NGLTRANSLATOR_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define NGLTRANSLATOR_EXPORT __attribute__((visibility("default")))
|
||||
# endif
|
||||
# endif
|
||||
#ifdef BUILD_STATIC_LIBRARIES
|
||||
#define NGLTRANSLATOR_EXPORT
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#ifdef MAKE_NGLTRANSLATOR_LIB
|
||||
#define NGLTRANSLATOR_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define NGLTRANSLATOR_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define NGLTRANSLATOR_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
Executable → Regular
+16
-19
@@ -9,26 +9,23 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class Translator final : public QTranslator
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Translator(QObject *parent = nullptr);
|
||||
class Translator final : public QTranslator
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Translator(QObject *parent = nullptr);
|
||||
|
||||
QString translate(const char *context,
|
||||
const char *sourceText,
|
||||
const char *disambiguation = nullptr,
|
||||
int n = -1) const override;
|
||||
QString translate(const char *context, const char *sourceText, const char *disambiguation = nullptr, int n = -1) const override;
|
||||
|
||||
void setTranslationCatalog(const TranslationCatalog &catalog);
|
||||
bool setTranslationDataJson(const QByteArray &jsonData, const QByteArray &md5Sum, bool bCompressed);
|
||||
|
||||
void isoCodeChanged(const QByteArray &isoCode);
|
||||
private:
|
||||
|
||||
QHash<QByteArray, QHash<QByteArray, QHash<QByteArray, QString>>> m_translationLookup;
|
||||
TranslationCatalog m_catalog;
|
||||
QByteArray m_md5Sum;
|
||||
};
|
||||
void setTranslationCatalog(const TranslationCatalog &catalog);
|
||||
bool setTranslationDataJson(const QByteArray &jsonData, const QByteArray &md5Sum, bool bCompressed);
|
||||
|
||||
void isoCodeChanged(const QByteArray &isoCode);
|
||||
|
||||
private:
|
||||
QHash<QByteArray, QHash<QByteArray, QHash<QByteArray, QString>>> m_translationLookup;
|
||||
TranslationCatalog m_catalog;
|
||||
QByteArray m_md5Sum;
|
||||
};
|
||||
|
||||
}
|
||||
Executable → Regular
+6
-10
@@ -15,8 +15,8 @@
|
||||
#include "ngldialogbuttonbox.h"
|
||||
|
||||
NGLDialog::NGLDialog(QWidget *parent, Qt::WindowFlags f)
|
||||
: QDialog(parent, f)
|
||||
, m_bReadOnly(false)
|
||||
: QDialog(parent, f)
|
||||
, m_bReadOnly(false)
|
||||
{
|
||||
setWindowIcon(QIcon(QLatin1String(":icons/16x16/rde_16x16.png")));
|
||||
}
|
||||
@@ -30,9 +30,7 @@ void NGLDialog::showEvent(QShowEvent *e)
|
||||
{
|
||||
NGLDialogButtonBox *bb = findChild<NGLDialogButtonBox *>();
|
||||
if (bb)
|
||||
connect(bb, &NGLDialogButtonBox::onHelp,
|
||||
this, &NGLDialog::onInvokeHelp,
|
||||
Qt::UniqueConnection);
|
||||
connect(bb, &NGLDialogButtonBox::onHelp, this, &NGLDialog::onInvokeHelp, Qt::UniqueConnection);
|
||||
QDialog::showEvent(e);
|
||||
}
|
||||
|
||||
@@ -40,9 +38,7 @@ void NGLDialog::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
if (e->key() == Qt::Key_F1)
|
||||
onInvokeHelp();
|
||||
if (e->key() == Qt::Key_P &&
|
||||
e->modifiers().testFlag(Qt::ControlModifier) &&
|
||||
e->modifiers().testFlag(Qt::AltModifier))
|
||||
if (e->key() == Qt::Key_P && e->modifiers().testFlag(Qt::ControlModifier) && e->modifiers().testFlag(Qt::AltModifier))
|
||||
printWidget();
|
||||
|
||||
QDialog::keyPressEvent(e);
|
||||
@@ -133,13 +129,13 @@ QString NGLDialog::windowTitle() const
|
||||
|
||||
void NGLDialog::setDialogReadOnly(bool bReadOnly, const QString &reason)
|
||||
{
|
||||
m_bReadOnly = bReadOnly;
|
||||
m_bReadOnly = bReadOnly;
|
||||
if (bReadOnly && !reason.isEmpty())
|
||||
m_readOnlyReason = reason;
|
||||
else
|
||||
m_readOnlyReason.clear();
|
||||
|
||||
setWindowTitle(windowTitle());
|
||||
setWindowTitle(windowTitle());
|
||||
}
|
||||
|
||||
bool NGLDialog::isDialogReadOnly() const
|
||||
|
||||
Executable → Regular
+7
-12
@@ -16,47 +16,42 @@ public:
|
||||
|
||||
void setHelpContext(const QString &helpContext);
|
||||
|
||||
|
||||
|
||||
static void centerWidget(QWidget *widgetToCenter);
|
||||
|
||||
|
||||
|
||||
static void printWidget(QWidget *widgetToPrint);
|
||||
|
||||
|
||||
|
||||
void setWindowTitle(const QString &title);
|
||||
|
||||
|
||||
|
||||
QString windowTitle() const;
|
||||
|
||||
|
||||
|
||||
void setDialogReadOnly(bool bReadOnly, const QString &reason = QString());
|
||||
|
||||
|
||||
|
||||
bool isDialogReadOnly() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
|
||||
|
||||
void invokeHelp(const QString &helpContext);
|
||||
|
||||
protected:
|
||||
virtual void showEvent(QShowEvent *e);
|
||||
virtual void keyPressEvent(QKeyEvent *e);
|
||||
void centerWidget();
|
||||
void printWidget();
|
||||
protected Q_SLOTS:
|
||||
|
||||
|
||||
|
||||
void onInvokeHelp();
|
||||
|
||||
private:
|
||||
QString m_helpContext;
|
||||
bool m_bReadOnly;
|
||||
QString m_readOnlyReason;
|
||||
QString m_realWindowTitle;
|
||||
QString m_helpContext;
|
||||
bool m_bReadOnly;
|
||||
QString m_readOnlyReason;
|
||||
QString m_realWindowTitle;
|
||||
};
|
||||
Executable → Regular
+106
-110
@@ -5,31 +5,29 @@
|
||||
#include <QtWidgets/QFrame>
|
||||
|
||||
NGLDialogButtonBox::NGLDialogButtonBox(QWidget *parent)
|
||||
: NGLDialogButtonBox(Qt::Horizontal, parent)
|
||||
{}
|
||||
: NGLDialogButtonBox(Qt::Horizontal, parent)
|
||||
{
|
||||
}
|
||||
|
||||
NGLDialogButtonBox::NGLDialogButtonBox(Qt::Orientation orientation,
|
||||
QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_orientation(orientation)
|
||||
, m_buttons(NGLStandardButton::NoButton)
|
||||
, m_line(nullptr)
|
||||
, m_bSpacer2ContextAction(nullptr)
|
||||
, m_bLineVisible(true)
|
||||
NGLDialogButtonBox::NGLDialogButtonBox(Qt::Orientation orientation, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_orientation(orientation)
|
||||
, m_buttons(NGLStandardButton::NoButton)
|
||||
, m_line(nullptr)
|
||||
, m_bSpacer2ContextAction(nullptr)
|
||||
, m_bLineVisible(true)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
init();
|
||||
}
|
||||
|
||||
NGLDialogButtonBox::NGLDialogButtonBox(NGLStandardButton::StandardButtons buttons,
|
||||
Qt::Orientation orientation,
|
||||
QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_orientation(orientation)
|
||||
, m_buttons(buttons)
|
||||
, m_line(nullptr)
|
||||
, m_bSpacer2ContextAction(nullptr)
|
||||
, m_bLineVisible(true)
|
||||
NGLDialogButtonBox::NGLDialogButtonBox(NGLStandardButton::StandardButtons buttons, Qt::Orientation orientation, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_orientation(orientation)
|
||||
, m_buttons(buttons)
|
||||
, m_line(nullptr)
|
||||
, m_bSpacer2ContextAction(nullptr)
|
||||
, m_bLineVisible(true)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
setStandardButtons(m_buttons);
|
||||
@@ -81,7 +79,7 @@ void NGLDialogButtonBox::setStandardButtons(NGLStandardButton::StandardButtons b
|
||||
button->setAutoDefault(true);
|
||||
}
|
||||
}
|
||||
i = (NGLStandardButton::StandardButton)((int) i << 1);
|
||||
i = (NGLStandardButton::StandardButton)((int)i << 1);
|
||||
}
|
||||
|
||||
init();
|
||||
@@ -118,7 +116,7 @@ NGLStandardButton *NGLDialogButtonBox::button(NGLStandardButton::StandardButton
|
||||
if (it.value()->type() == button)
|
||||
return it.value();
|
||||
}
|
||||
return new NGLStandardButton(nullptr);
|
||||
return new NGLStandardButton(nullptr);
|
||||
}
|
||||
|
||||
void NGLDialogButtonBox::removeFromActionList(NGLStandardButton::StandardButton button)
|
||||
@@ -192,7 +190,8 @@ static void addSpacer2(QLayout *l, Qt::Orientation orientation)
|
||||
void NGLDialogButtonBox::init()
|
||||
{
|
||||
delete layout();
|
||||
delete m_line; m_line = nullptr;
|
||||
delete m_line;
|
||||
m_line = nullptr;
|
||||
if (m_bSpacer2ContextAction)
|
||||
{
|
||||
removeAction(m_bSpacer2ContextAction);
|
||||
@@ -212,7 +211,7 @@ void NGLDialogButtonBox::init()
|
||||
lMain = new QHBoxLayout;
|
||||
l = new QVBoxLayout;
|
||||
}
|
||||
lMain->setContentsMargins(0,0,0,0);
|
||||
lMain->setContentsMargins(0, 0, 0, 0);
|
||||
if (m_bLineVisible)
|
||||
{
|
||||
m_line = new QFrame(this);
|
||||
@@ -225,7 +224,7 @@ void NGLDialogButtonBox::init()
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(lMain);
|
||||
|
||||
const auto actions = findChildren<QAction*>();
|
||||
const auto actions = findChildren<QAction *>();
|
||||
for (auto a : actions)
|
||||
a->disconnect(a, &QAction::triggered, this, &NGLDialogButtonBox::buttonClicked);
|
||||
|
||||
@@ -246,7 +245,7 @@ void NGLDialogButtonBox::init()
|
||||
bSpacer1Added = true;
|
||||
if (bLowestPrioButton)
|
||||
{
|
||||
|
||||
|
||||
QSpacerItem *item = new QSpacerItem(7, 7, QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
l->addItem(item);
|
||||
}
|
||||
@@ -256,10 +255,10 @@ void NGLDialogButtonBox::init()
|
||||
bSpacer2Added = true;
|
||||
addSpacer2(l, m_orientation);
|
||||
}
|
||||
|
||||
|
||||
if (prio >= 30 && prio < 100)
|
||||
{
|
||||
|
||||
|
||||
const QList<QAction *> actions = button->actions();
|
||||
for (QAction *a : actions)
|
||||
removeAction(a);
|
||||
@@ -276,26 +275,23 @@ void NGLDialogButtonBox::init()
|
||||
}
|
||||
}
|
||||
l->addWidget(button);
|
||||
|
||||
|
||||
if (button->type() == NGLStandardButton::Library)
|
||||
{
|
||||
QAction *ex = button->findChild<QAction *>(QLatin1String("actionExport"));
|
||||
if (ex)
|
||||
{
|
||||
connect(ex, &QAction::triggered,
|
||||
this, &NGLDialogButtonBox::buttonClicked, Qt::UniqueConnection);
|
||||
connect(ex, &QAction::triggered, this, &NGLDialogButtonBox::buttonClicked, Qt::UniqueConnection);
|
||||
}
|
||||
QAction *im = button->findChild<QAction *>(QLatin1String("actionImport"));
|
||||
if (im)
|
||||
{
|
||||
connect(im, &QAction::triggered,
|
||||
this, &NGLDialogButtonBox::buttonClicked, Qt::UniqueConnection);
|
||||
connect(im, &QAction::triggered, this, &NGLDialogButtonBox::buttonClicked, Qt::UniqueConnection);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
connect(button, &NGLStandardButton::clicked,
|
||||
this, &NGLDialogButtonBox::buttonClicked, Qt::UniqueConnection);
|
||||
connect(button, &NGLStandardButton::clicked, this, &NGLDialogButtonBox::buttonClicked, Qt::UniqueConnection);
|
||||
}
|
||||
}
|
||||
if (!bSpacer2Added)
|
||||
@@ -315,10 +311,10 @@ void NGLDialogButtonBox::init()
|
||||
|
||||
void NGLDialogButtonBox::buttonClicked()
|
||||
{
|
||||
NGLStandardButton *b = qobject_cast<NGLStandardButton *> (sender());
|
||||
NGLStandardButton *b = qobject_cast<NGLStandardButton *>(sender());
|
||||
if (!b)
|
||||
{
|
||||
QAction *a = qobject_cast<QAction *> (sender());
|
||||
QAction *a = qobject_cast<QAction *>(sender());
|
||||
if (!a)
|
||||
return;
|
||||
if (a->objectName() == QLatin1String("actionExport"))
|
||||
@@ -335,80 +331,80 @@ void NGLDialogButtonBox::buttonClicked()
|
||||
}
|
||||
switch (b->type())
|
||||
{
|
||||
case NGLStandardButton::Ok:
|
||||
emit onOk();
|
||||
break;
|
||||
case NGLStandardButton::Send:
|
||||
emit onSend();
|
||||
break;
|
||||
case NGLStandardButton::New:
|
||||
emit onNew();
|
||||
break;
|
||||
case NGLStandardButton::Delete:
|
||||
emit onDelete();
|
||||
break;
|
||||
case NGLStandardButton::Save:
|
||||
emit onSave();
|
||||
break;
|
||||
case NGLStandardButton::Open:
|
||||
emit onOpen();
|
||||
break;
|
||||
case NGLStandardButton::Yes:
|
||||
emit onYes();
|
||||
break;
|
||||
case NGLStandardButton::No:
|
||||
emit onNo();
|
||||
break;
|
||||
case NGLStandardButton::Close:
|
||||
emit onClose();
|
||||
break;
|
||||
case NGLStandardButton::Cancel:
|
||||
emit onCancel();
|
||||
break;
|
||||
case NGLStandardButton::Help:
|
||||
emit onHelp();
|
||||
break;
|
||||
case NGLStandardButton::Apply:
|
||||
emit onApply();
|
||||
break;
|
||||
case NGLStandardButton::Reset:
|
||||
emit onReset();
|
||||
break;
|
||||
case NGLStandardButton::Print:
|
||||
emit onPrint();
|
||||
break;
|
||||
case NGLStandardButton::Modify:
|
||||
emit onModify();
|
||||
break;
|
||||
case NGLStandardButton::Add:
|
||||
emit onAdd();
|
||||
break;
|
||||
case NGLStandardButton::Remove:
|
||||
emit onRemove();
|
||||
break;
|
||||
case NGLStandardButton::Edit:
|
||||
emit onEdit();
|
||||
break;
|
||||
case NGLStandardButton::Download:
|
||||
emit onDownload();
|
||||
break;
|
||||
case NGLStandardButton::Library:
|
||||
break;
|
||||
case NGLStandardButton::Show:
|
||||
emit onShow();
|
||||
break;
|
||||
case NGLStandardButton::ZoomIn:
|
||||
emit onZoomIn();
|
||||
break;
|
||||
case NGLStandardButton::ZoomOut:
|
||||
emit onZoomOut();
|
||||
break;
|
||||
case NGLStandardButton::Hide:
|
||||
emit onHide();
|
||||
break;
|
||||
default:
|
||||
emit clicked(b);
|
||||
break;
|
||||
case NGLStandardButton::Ok:
|
||||
emit onOk();
|
||||
break;
|
||||
case NGLStandardButton::Send:
|
||||
emit onSend();
|
||||
break;
|
||||
case NGLStandardButton::New:
|
||||
emit onNew();
|
||||
break;
|
||||
case NGLStandardButton::Delete:
|
||||
emit onDelete();
|
||||
break;
|
||||
case NGLStandardButton::Save:
|
||||
emit onSave();
|
||||
break;
|
||||
case NGLStandardButton::Open:
|
||||
emit onOpen();
|
||||
break;
|
||||
case NGLStandardButton::Yes:
|
||||
emit onYes();
|
||||
break;
|
||||
case NGLStandardButton::No:
|
||||
emit onNo();
|
||||
break;
|
||||
case NGLStandardButton::Close:
|
||||
emit onClose();
|
||||
break;
|
||||
case NGLStandardButton::Cancel:
|
||||
emit onCancel();
|
||||
break;
|
||||
case NGLStandardButton::Help:
|
||||
emit onHelp();
|
||||
break;
|
||||
case NGLStandardButton::Apply:
|
||||
emit onApply();
|
||||
break;
|
||||
case NGLStandardButton::Reset:
|
||||
emit onReset();
|
||||
break;
|
||||
case NGLStandardButton::Print:
|
||||
emit onPrint();
|
||||
break;
|
||||
case NGLStandardButton::Modify:
|
||||
emit onModify();
|
||||
break;
|
||||
case NGLStandardButton::Add:
|
||||
emit onAdd();
|
||||
break;
|
||||
case NGLStandardButton::Remove:
|
||||
emit onRemove();
|
||||
break;
|
||||
case NGLStandardButton::Edit:
|
||||
emit onEdit();
|
||||
break;
|
||||
case NGLStandardButton::Download:
|
||||
emit onDownload();
|
||||
break;
|
||||
case NGLStandardButton::Library:
|
||||
break;
|
||||
case NGLStandardButton::Show:
|
||||
emit onShow();
|
||||
break;
|
||||
case NGLStandardButton::ZoomIn:
|
||||
emit onZoomIn();
|
||||
break;
|
||||
case NGLStandardButton::ZoomOut:
|
||||
emit onZoomOut();
|
||||
break;
|
||||
case NGLStandardButton::Hide:
|
||||
emit onHide();
|
||||
break;
|
||||
default:
|
||||
emit clicked(b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+27
-46
@@ -17,155 +17,138 @@ class NGLWIDGETS_EXPORT NGLDialogButtonBox : public QWidget
|
||||
Q_PROPERTY(bool m_bLineVisible READ lineVisible WRITE setLineVisible)
|
||||
|
||||
public:
|
||||
|
||||
|
||||
explicit NGLDialogButtonBox(QWidget *parent = nullptr);
|
||||
|
||||
|
||||
|
||||
explicit NGLDialogButtonBox(Qt::Orientation orientation, QWidget *parent = nullptr);
|
||||
|
||||
|
||||
|
||||
NGLDialogButtonBox(NGLStandardButton::StandardButtons buttons, Qt::Orientation orientation = Qt::Horizontal, QWidget *parent = nullptr);
|
||||
|
||||
|
||||
|
||||
Qt::Orientation orientation() const;
|
||||
|
||||
|
||||
|
||||
void setOrientation(Qt::Orientation orientation);
|
||||
|
||||
|
||||
|
||||
NGLStandardButton::StandardButtons standardButtons() const;
|
||||
|
||||
|
||||
|
||||
void setStandardButtons(NGLStandardButton::StandardButtons buttons);
|
||||
|
||||
|
||||
|
||||
void addButton(NGLStandardButton *button);
|
||||
|
||||
|
||||
|
||||
NGLStandardButton *addButton(NGLStandardButton::StandardButton button);
|
||||
|
||||
|
||||
|
||||
NGLStandardButton *button(NGLStandardButton::StandardButton button);
|
||||
|
||||
|
||||
|
||||
void removeFromActionList(NGLStandardButton::StandardButton button);
|
||||
|
||||
|
||||
|
||||
bool setEnabled(NGLStandardButton::StandardButton button, bool enable);
|
||||
|
||||
|
||||
|
||||
bool isEnabled(NGLStandardButton::StandardButton button);
|
||||
|
||||
|
||||
|
||||
bool lineVisible() const;
|
||||
|
||||
|
||||
|
||||
void setLineVisible(bool bVisible);
|
||||
|
||||
|
||||
|
||||
bool setVisible(NGLStandardButton::StandardButton button, bool visible);
|
||||
|
||||
|
||||
|
||||
void setVisible(bool visible) { QWidget::setVisible(visible); }
|
||||
|
||||
|
||||
|
||||
void enableExport(bool ena);
|
||||
|
||||
|
||||
|
||||
void enableImport(bool ena);
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
|
||||
|
||||
void layoutPriorityChanged();
|
||||
Q_SIGNALS:
|
||||
|
||||
|
||||
|
||||
void clicked(NGLStandardButton *button);
|
||||
|
||||
|
||||
|
||||
void onOk();
|
||||
|
||||
|
||||
|
||||
void onSend();
|
||||
|
||||
|
||||
|
||||
void onNew();
|
||||
|
||||
|
||||
|
||||
void onDelete();
|
||||
|
||||
|
||||
|
||||
void onSave();
|
||||
|
||||
|
||||
|
||||
void onOpen();
|
||||
|
||||
|
||||
|
||||
void onYes();
|
||||
|
||||
|
||||
|
||||
void onNo();
|
||||
|
||||
|
||||
|
||||
void onClose();
|
||||
|
||||
|
||||
|
||||
void onCancel();
|
||||
|
||||
|
||||
|
||||
void onHelp();
|
||||
|
||||
|
||||
|
||||
void onApply();
|
||||
|
||||
|
||||
|
||||
void onReset();
|
||||
|
||||
|
||||
|
||||
void onPrint();
|
||||
|
||||
|
||||
|
||||
void onModify();
|
||||
|
||||
|
||||
|
||||
void onAdd();
|
||||
|
||||
|
||||
|
||||
void onRemove();
|
||||
|
||||
|
||||
|
||||
void onEdit();
|
||||
|
||||
|
||||
|
||||
void onDownload();
|
||||
|
||||
|
||||
|
||||
void onLibraryImport();
|
||||
|
||||
|
||||
|
||||
void onLibraryExport();
|
||||
|
||||
void onShow();
|
||||
void onZoomIn();
|
||||
void onZoomOut();
|
||||
|
||||
|
||||
|
||||
void onHide();
|
||||
|
||||
@@ -185,5 +168,3 @@ protected:
|
||||
QAction *m_bSpacer2ContextAction;
|
||||
bool m_bLineVisible;
|
||||
};
|
||||
|
||||
|
||||
Executable → Regular
+24
-24
@@ -12,21 +12,28 @@
|
||||
#include <QtWidgets/QMenuBar>
|
||||
|
||||
NGLMainWindow::NGLMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, m_helpProcess(nullptr)
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger())
|
||||
, m_versionView(nullptr)
|
||||
, m_menuBar(new QMenuBar(this))
|
||||
: QMainWindow(parent)
|
||||
, m_helpProcess(nullptr)
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger())
|
||||
, m_versionView(nullptr)
|
||||
, m_menuBar(new QMenuBar(this))
|
||||
{
|
||||
m_menu[QLatin1String("File")] = m_menuBar->addMenu(tr("File"));
|
||||
m_fileActionBefore = m_menu[QLatin1String("File")]->addSeparator();
|
||||
m_menu[QLatin1String("File")]->addAction(QIcon(QLatin1String(":/icons/16x16/application-exit.png")), tr("Quit"), QKeySequence(tr("Ctrl+q")), this, &NGLMainWindow::onExit);
|
||||
m_menu[QLatin1String("File")]->addAction(QIcon(QLatin1String(":/icons/16x16/application-exit.png")),
|
||||
tr("Quit"),
|
||||
QKeySequence(tr("Ctrl+q")),
|
||||
this,
|
||||
&NGLMainWindow::onExit);
|
||||
|
||||
m_menu[QLatin1String("Help")] = m_menuBar->addMenu(tr("Help"));
|
||||
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-contents.png")), tr("Help"), QKeySequence(tr("F1")), this, &NGLMainWindow::onHelpIndex);
|
||||
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-contents.png")),
|
||||
tr("Help"),
|
||||
QKeySequence(tr("F1")),
|
||||
this,
|
||||
&NGLMainWindow::onHelpIndex);
|
||||
m_menu[QLatin1String("Help")]->addSeparator();
|
||||
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-about.png")),
|
||||
tr("About"), this, &NGLMainWindow::onHelpAbout);
|
||||
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-about.png")), tr("About"), this, &NGLMainWindow::onHelpAbout);
|
||||
|
||||
setWindowIcon(QIcon(QLatin1String(":icons/16x16/rde_16x16.png")));
|
||||
setMenuBar(m_menuBar);
|
||||
@@ -34,7 +41,7 @@ NGLMainWindow::NGLMainWindow(QWidget *parent)
|
||||
|
||||
void NGLMainWindow::onExit()
|
||||
{
|
||||
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
@@ -45,8 +52,8 @@ void NGLMainWindow::onHelpIndex()
|
||||
|
||||
void NGLMainWindow::onInvokeHelp(const QString &helpContext)
|
||||
{
|
||||
|
||||
DEBUG_LOG(m_logger) << "onInvokeHelp " << helpContext ;
|
||||
|
||||
DEBUG_LOG(m_logger) << "onInvokeHelp " << helpContext;
|
||||
|
||||
if (!m_helpProcess)
|
||||
{
|
||||
@@ -58,22 +65,17 @@ void NGLMainWindow::onInvokeHelp(const QString &helpContext)
|
||||
m_helpProcess->setProcessEnvironment(env);
|
||||
QStringList args;
|
||||
QString fn = QString::fromLatin1(NGL::translationLocale()) + QLatin1String(".qhc");
|
||||
args << QLatin1String("-collectionFile")
|
||||
<< QCoreApplication::applicationDirPath() + QLatin1String("/../help/scms/") + fn
|
||||
<< QLatin1String("-enableRemoteControl");
|
||||
DEBUG_LOG(m_logger) << "Attempting to invoke help at URL: " << args.join(QLatin1String(" ")) ;
|
||||
args << QLatin1String("-collectionFile") << QCoreApplication::applicationDirPath() + QLatin1String("/../help/scms/") + fn << QLatin1String("-enableRemoteControl");
|
||||
DEBUG_LOG(m_logger) << "Attempting to invoke help at URL: " << args.join(QLatin1String(" "));
|
||||
m_helpProcess->start(QLibraryInfo::path(QLibraryInfo::BinariesPath) + QLatin1String("/assistant"), args);
|
||||
if (!m_helpProcess->waitForStarted())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not start help browser (error: "
|
||||
<< m_helpProcess->error()
|
||||
<< " )" ;
|
||||
ERROR_LOG(m_logger) << "Could not start help browser (error: " << m_helpProcess->error() << " )";
|
||||
delete m_helpProcess;
|
||||
m_helpProcess = nullptr;
|
||||
return;
|
||||
}
|
||||
connect(m_helpProcess, QOverload<int,QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
this, &NGLMainWindow::onHelpFinished);
|
||||
connect(m_helpProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &NGLMainWindow::onHelpFinished);
|
||||
}
|
||||
QTextStream str(m_helpProcess);
|
||||
|
||||
@@ -85,9 +87,7 @@ void NGLMainWindow::onHelpFinished(int exitCode, QProcess::ExitStatus exitStatus
|
||||
{
|
||||
if (exitStatus != QProcess::NormalExit)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "help browser exited with status "
|
||||
<< exitStatus << " code "
|
||||
<< exitCode << "!" ;
|
||||
WARNING_LOG(m_logger) << "help browser exited with status " << exitStatus << " code " << exitCode << "!";
|
||||
}
|
||||
delete m_helpProcess;
|
||||
m_helpProcess = nullptr;
|
||||
|
||||
Executable → Regular
+6
-8
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
class NGLWIDGETS_EXPORT NGLMainWindow : public QMainWindow
|
||||
@@ -29,18 +29,16 @@ public slots:
|
||||
void onHelpFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
|
||||
private:
|
||||
QProcess *m_helpProcess;
|
||||
QProcess *m_helpProcess;
|
||||
|
||||
protected:
|
||||
NGL::INGLLogger &m_logger;
|
||||
QWidget *m_versionView;
|
||||
QMenuBar *m_menuBar;
|
||||
QMap<QString, QMenu *> m_menu;
|
||||
QAction *m_fileActionBefore;
|
||||
QWidget *m_versionView;
|
||||
QMenuBar *m_menuBar;
|
||||
QMap<QString, QMenu *> m_menu;
|
||||
QAction *m_fileActionBefore;
|
||||
|
||||
protected slots:
|
||||
void onVersionViewDeleted();
|
||||
void onExit();
|
||||
|
||||
};
|
||||
|
||||
Executable → Regular
+345
-351
@@ -16,393 +16,387 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
PDFDocument::PDFDocument(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_doc(nullptr)
|
||||
, m_currentPage(0)
|
||||
, m_maxCachedPages(20)
|
||||
, m_scaleFactor(1.0)
|
||||
, m_widthFactor(1.0)
|
||||
PDFDocument::PDFDocument(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_doc(nullptr)
|
||||
, m_currentPage(0)
|
||||
, m_maxCachedPages(20)
|
||||
, m_scaleFactor(1.0)
|
||||
, m_widthFactor(1.0)
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
, m_rotation(Poppler::Page::Rotate0)
|
||||
, m_rotation(Poppler::Page::Rotate0)
|
||||
#endif
|
||||
{
|
||||
QVBoxLayout *lay = new QVBoxLayout(this);
|
||||
lay->setContentsMargins(0,0,0,0);
|
||||
lay->setSpacing(0);
|
||||
|
||||
m_pdfLabel = new QWidget(this);
|
||||
m_pdfLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
QVBoxLayout *l = new QVBoxLayout(m_pdfLabel);
|
||||
const int innerMargin = 6;
|
||||
l->setContentsMargins(innerMargin, innerMargin, innerMargin, innerMargin);
|
||||
l->setSpacing(innerMargin);
|
||||
l->setSizeConstraint(QLayout::SetFixedSize);
|
||||
|
||||
m_scrollArea = new QScrollArea(this);
|
||||
m_scrollArea->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
|
||||
m_scrollArea->setWidgetResizable(true);
|
||||
m_scrollArea->setWidget(m_pdfLabel);
|
||||
|
||||
lay->addWidget(m_scrollArea);
|
||||
}
|
||||
|
||||
PDFDocument::~PDFDocument()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
qDeleteAll(m_pages);
|
||||
m_pages.clear();
|
||||
#endif
|
||||
m_doc.reset();
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDF(const QUrl &url)
|
||||
{
|
||||
return showPDF(url.toLocalFile());
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDF(const QString &path)
|
||||
{
|
||||
if (path.isEmpty())
|
||||
return false;
|
||||
|
||||
if (path == m_currentPath)
|
||||
{
|
||||
m_scaleFactor = 0;
|
||||
m_widthFactor = 1;
|
||||
setZoomFactor(1.0);
|
||||
QVBoxLayout *lay = new QVBoxLayout(this);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
lay->setSpacing(0);
|
||||
|
||||
m_pdfLabel = new QWidget(this);
|
||||
m_pdfLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
QVBoxLayout *l = new QVBoxLayout(m_pdfLabel);
|
||||
const int innerMargin = 6;
|
||||
l->setContentsMargins(innerMargin, innerMargin, innerMargin, innerMargin);
|
||||
l->setSpacing(innerMargin);
|
||||
l->setSizeConstraint(QLayout::SetFixedSize);
|
||||
|
||||
m_scrollArea = new QScrollArea(this);
|
||||
m_scrollArea->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
|
||||
m_scrollArea->setWidgetResizable(true);
|
||||
m_scrollArea->setWidget(m_pdfLabel);
|
||||
|
||||
lay->addWidget(m_scrollArea);
|
||||
}
|
||||
|
||||
PDFDocument::~PDFDocument()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
setRotation(Poppler::Page::Rotate0);
|
||||
qDeleteAll(m_pages);
|
||||
m_pages.clear();
|
||||
#endif
|
||||
m_doc.reset();
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDF(const QUrl &url)
|
||||
{
|
||||
return showPDF(url.toLocalFile());
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDF(const QString &path)
|
||||
{
|
||||
if (path.isEmpty())
|
||||
return false;
|
||||
|
||||
if (path == m_currentPath)
|
||||
{
|
||||
m_scaleFactor = 0;
|
||||
m_widthFactor = 1;
|
||||
setZoomFactor(1.0);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
setRotation(Poppler::Page::Rotate0);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
m_doc = Poppler::Document::load(path);
|
||||
if (!m_doc)
|
||||
return false;
|
||||
m_currentPath = path;
|
||||
|
||||
return showPDFInternal();
|
||||
#else
|
||||
Q_UNUSED(path);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDF(const QByteArray &pdf)
|
||||
{
|
||||
m_currentPath.clear();
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
m_doc = Poppler::Document::loadFromData(pdf);
|
||||
if (!m_doc)
|
||||
return false;
|
||||
|
||||
return showPDFInternal();
|
||||
#else
|
||||
Q_UNUSED(pdf);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDFInternal()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
disconnect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this, &PDFDocument::onVSliderValueChanged);
|
||||
|
||||
m_doc->setRenderHint(Poppler::Document::Antialiasing);
|
||||
m_doc->setRenderHint(Poppler::Document::TextAntialiasing);
|
||||
m_doc->setRenderHint(Poppler::Document::TextHinting);
|
||||
m_doc->setRenderHint(Poppler::Document::TextSlightHinting);
|
||||
|
||||
m_scrollArea->horizontalScrollBar()->setSliderPosition(0);
|
||||
m_scrollArea->verticalScrollBar()->setSliderPosition(0);
|
||||
|
||||
m_renderedPages.clear();
|
||||
qDeleteAll(m_pages);
|
||||
m_pages.clear();
|
||||
m_ranges.clear();
|
||||
|
||||
QVBoxLayout *l = qobject_cast<QVBoxLayout *>(m_pdfLabel->layout());
|
||||
const int cnt = m_doc->numPages();
|
||||
m_pages.reserve(cnt);
|
||||
for (int i = 0; i < cnt; ++i)
|
||||
{
|
||||
PDFPage *p = new PDFPage(m_pdfLabel);
|
||||
p->setZoomFactor(m_scaleFactor);
|
||||
p->setRotation(m_rotation);
|
||||
auto pagePtr = m_doc->page(i);
|
||||
// transfer ownership of Poppler::Page to PDFPage; PDFPage will delete it
|
||||
p->setPopplerPage(pagePtr.release());
|
||||
connect(p, &PDFPage::pageRendered, this, &PDFDocument::onPageRendered);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
connect(p, &PDFPage::externalLinkClicked, this, &PDFDocument::linkClicked);
|
||||
connect(p, &PDFPage::linkClicked, this, &PDFDocument::onLinkClicked);
|
||||
#endif
|
||||
m_pages += p;
|
||||
|
||||
l->addWidget(p);
|
||||
}
|
||||
rebuildRanges();
|
||||
|
||||
m_currentPage = std::min(m_currentPage, static_cast<int>(m_ranges.count() - 1));
|
||||
|
||||
ensureCurPageVisible();
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
connect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this, &PDFDocument::onVSliderValueChanged);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
m_doc = Poppler::Document::load(path);
|
||||
if (!m_doc)
|
||||
return false;
|
||||
m_currentPath = path;
|
||||
|
||||
return showPDFInternal();
|
||||
#else
|
||||
Q_UNUSED(path);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDF(const QByteArray &pdf)
|
||||
{
|
||||
m_currentPath.clear();
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
m_doc = Poppler::Document::loadFromData(pdf);
|
||||
if (!m_doc)
|
||||
return false;
|
||||
|
||||
return showPDFInternal();
|
||||
#else
|
||||
Q_UNUSED(pdf);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDFInternal()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
disconnect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this, &PDFDocument::onVSliderValueChanged);
|
||||
|
||||
m_doc->setRenderHint(Poppler::Document::Antialiasing);
|
||||
m_doc->setRenderHint(Poppler::Document::TextAntialiasing);
|
||||
m_doc->setRenderHint(Poppler::Document::TextHinting);
|
||||
m_doc->setRenderHint(Poppler::Document::TextSlightHinting);
|
||||
|
||||
m_scrollArea->horizontalScrollBar()->setSliderPosition(0);
|
||||
m_scrollArea->verticalScrollBar()->setSliderPosition(0);
|
||||
|
||||
m_renderedPages.clear();
|
||||
qDeleteAll(m_pages);
|
||||
m_pages.clear();
|
||||
m_ranges.clear();
|
||||
|
||||
QVBoxLayout *l = qobject_cast<QVBoxLayout *> (m_pdfLabel->layout());
|
||||
const int cnt = m_doc->numPages();
|
||||
m_pages.reserve(cnt);
|
||||
for (int i = 0; i < cnt; ++i)
|
||||
void PDFDocument::resizePdfToWidth()
|
||||
{
|
||||
PDFPage *p = new PDFPage(m_pdfLabel);
|
||||
p->setZoomFactor(m_scaleFactor);
|
||||
p->setRotation(m_rotation);
|
||||
auto pagePtr = m_doc->page(i);
|
||||
// transfer ownership of Poppler::Page to PDFPage; PDFPage will delete it
|
||||
p->setPopplerPage(pagePtr.release());
|
||||
connect(p, &PDFPage::pageRendered,
|
||||
this, &PDFDocument::onPageRendered);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
connect(p, &PDFPage::externalLinkClicked,
|
||||
this, &PDFDocument::linkClicked);
|
||||
connect(p, &PDFPage::linkClicked,
|
||||
this, &PDFDocument::onLinkClicked);
|
||||
#endif
|
||||
m_pages += p;
|
||||
double scale = m_scaleFactor;
|
||||
|
||||
l->addWidget(p);
|
||||
m_widthFactor = double(m_pdfLabel->size().width()) / size().width() * 1.03;
|
||||
|
||||
m_scaleFactor = 0;
|
||||
setZoomFactor(scale);
|
||||
}
|
||||
rebuildRanges();
|
||||
|
||||
m_currentPage = std::min(m_currentPage, static_cast<int>(m_ranges.count() - 1));
|
||||
|
||||
ensureCurPageVisible();
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
connect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this, &PDFDocument::onVSliderValueChanged);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void PDFDocument::resizePdfToWidth()
|
||||
{
|
||||
double scale = m_scaleFactor;
|
||||
|
||||
m_widthFactor = double(m_pdfLabel->size().width()) / size().width() * 1.03;
|
||||
|
||||
m_scaleFactor = 0;
|
||||
setZoomFactor(scale);
|
||||
}
|
||||
|
||||
int PDFDocument::curPage() const
|
||||
{
|
||||
return m_currentPage + 1;
|
||||
}
|
||||
|
||||
int PDFDocument::numPages() const
|
||||
{
|
||||
// Return 0 when no document is loaded to satisfy tests that expect a non-negative page count
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
return m_doc ? m_doc->numPages() : 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::setZoomFactor(double zoom)
|
||||
{
|
||||
if (qFuzzyCompare(m_scaleFactor, zoom))
|
||||
return;
|
||||
m_scaleFactor = zoom;
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
for (PDFPage *p : std::as_const(m_pages))
|
||||
p->setZoomFactor(m_scaleFactor / m_widthFactor);
|
||||
|
||||
rebuildRanges();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::setRotation(Poppler::Page::Rotation rot)
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_rotation == rot)
|
||||
return;
|
||||
m_rotation = rot;
|
||||
if (m_pages.isEmpty())
|
||||
return;
|
||||
|
||||
for (PDFPage *p : std::as_const(m_pages))
|
||||
p->setRotation(m_rotation);
|
||||
|
||||
rebuildRanges();
|
||||
emit currentPageChanged(m_currentPage+1, m_ranges.count());
|
||||
emit rotationChanged(m_rotation);
|
||||
#else
|
||||
Q_UNUSED(rot);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::setPage(int page)
|
||||
{
|
||||
page--;
|
||||
if (m_currentPage == page)
|
||||
int PDFDocument::curPage() const
|
||||
{
|
||||
return m_currentPage + 1;
|
||||
}
|
||||
|
||||
int PDFDocument::numPages() const
|
||||
{
|
||||
// Return 0 when no document is loaded to satisfy tests that expect a non-negative page count
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
return m_doc ? m_doc->numPages() : 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::setZoomFactor(double zoom)
|
||||
{
|
||||
if (qFuzzyCompare(m_scaleFactor, zoom))
|
||||
return;
|
||||
m_scaleFactor = zoom;
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
for (PDFPage *p : std::as_const(m_pages))
|
||||
p->setZoomFactor(m_scaleFactor / m_widthFactor);
|
||||
|
||||
rebuildRanges();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::setRotation(Poppler::Page::Rotation rot)
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_rotation == rot)
|
||||
return;
|
||||
m_rotation = rot;
|
||||
if (m_pages.isEmpty())
|
||||
return;
|
||||
|
||||
for (PDFPage *p : std::as_const(m_pages))
|
||||
p->setRotation(m_rotation);
|
||||
|
||||
rebuildRanges();
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
emit rotationChanged(m_rotation);
|
||||
#else
|
||||
Q_UNUSED(rot);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::setPage(int page)
|
||||
{
|
||||
page--;
|
||||
if (m_currentPage == page)
|
||||
{
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
}
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_pages.isEmpty())
|
||||
{
|
||||
m_currentPage = page;
|
||||
return true;
|
||||
}
|
||||
if (page < 0 || numPages() < 0 || page >= m_doc->numPages())
|
||||
return false;
|
||||
|
||||
m_currentPage = page;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
#else
|
||||
Q_UNUSED(page);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_pages.isEmpty())
|
||||
|
||||
bool PDFDocument::nextPage()
|
||||
{
|
||||
m_currentPage = page;
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_doc == nullptr || m_currentPage >= m_doc->numPages() - 1)
|
||||
return false;
|
||||
m_currentPage++;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
if (page < 0 || numPages() < 0 || page >= m_doc->numPages())
|
||||
return false;
|
||||
|
||||
m_currentPage = page;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
#else
|
||||
Q_UNUSED(page);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::nextPage()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_doc == nullptr || m_currentPage >= m_doc->numPages() - 1)
|
||||
return false;
|
||||
m_currentPage++;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::previousPage()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_doc == nullptr || m_currentPage < 1)
|
||||
return false;
|
||||
m_currentPage--;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::onVSliderValueChanged(int y)
|
||||
{
|
||||
|
||||
y += m_scrollArea->height() / 2;
|
||||
int curPage = m_ranges.count() - 1;
|
||||
for (int i = 0; i < m_ranges.count(); ++i)
|
||||
bool PDFDocument::previousPage()
|
||||
{
|
||||
if (m_ranges.at(i) > y)
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_doc == nullptr || m_currentPage < 1)
|
||||
return false;
|
||||
m_currentPage--;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::onVSliderValueChanged(int y)
|
||||
{
|
||||
|
||||
y += m_scrollArea->height() / 2;
|
||||
int curPage = m_ranges.count() - 1;
|
||||
for (int i = 0; i < m_ranges.count(); ++i)
|
||||
{
|
||||
curPage = i - 1;
|
||||
break;
|
||||
if (m_ranges.at(i) > y)
|
||||
{
|
||||
curPage = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (curPage != m_currentPage && curPage >= 0)
|
||||
{
|
||||
m_currentPage = curPage;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
}
|
||||
}
|
||||
if (curPage != m_currentPage && curPage >= 0)
|
||||
|
||||
void PDFDocument::onPageRendered()
|
||||
{
|
||||
m_currentPage = curPage;
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
PDFPage *p = qobject_cast<PDFPage *>(sender());
|
||||
if (m_renderedPages.contains(p))
|
||||
return;
|
||||
|
||||
while (m_renderedPages.count() > m_maxCachedPages - 1)
|
||||
{
|
||||
p = m_renderedPages.takeFirst();
|
||||
if (p)
|
||||
p->clearPixmap();
|
||||
}
|
||||
m_renderedPages.push_back(p);
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::onLinkClicked(const Poppler::LinkDestination &dest)
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
PDFPage *p = qobject_cast<PDFPage *>(sender());
|
||||
if (!p)
|
||||
return;
|
||||
m_currentPage = dest.pageNumber() - 1;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible(qRound(dest.right() * p->width()), qRound(dest.top() * p->height()));
|
||||
#else
|
||||
Q_UNUSED(dest);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void PDFDocument::onPageRendered()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
PDFPage *p = qobject_cast<PDFPage *> (sender());
|
||||
if (m_renderedPages.contains(p))
|
||||
return;
|
||||
|
||||
while (m_renderedPages.count() > m_maxCachedPages - 1)
|
||||
QVector<QImage> PDFDocument::getPrintableImages(int resolution) const
|
||||
{
|
||||
p = m_renderedPages.takeFirst();
|
||||
if (p)
|
||||
p->clearPixmap();
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
QVector<QImage> imageList;
|
||||
imageList.reserve(m_pages.size());
|
||||
for (const PDFPage *p : m_pages)
|
||||
imageList.append(p->getPrintableImage(resolution));
|
||||
return imageList;
|
||||
#else
|
||||
Q_UNUSED(resolution);
|
||||
return QVector<QImage>();
|
||||
#endif
|
||||
}
|
||||
m_renderedPages.push_back(p);
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::onLinkClicked(const Poppler::LinkDestination &dest)
|
||||
{
|
||||
QImage PDFDocument::getPrintableImage(int pageNum, int resolution) const
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
PDFPage *p = qobject_cast<PDFPage *>(sender());
|
||||
if (!p)
|
||||
return;
|
||||
m_currentPage = dest.pageNumber() - 1;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible(qRound(dest.right() * p->width()),
|
||||
qRound(dest.top() * p->height()));
|
||||
if (pageNum < 0 || pageNum >= m_pages.size())
|
||||
return QImage();
|
||||
return m_pages[pageNum]->getPrintableImage(resolution);
|
||||
#else
|
||||
Q_UNUSED(dest);
|
||||
#endif
|
||||
}
|
||||
|
||||
QVector<QImage> PDFDocument::getPrintableImages(int resolution) const
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
QVector<QImage> imageList;
|
||||
imageList.reserve(m_pages.size());
|
||||
for (const PDFPage *p : m_pages)
|
||||
imageList.append(p->getPrintableImage(resolution));
|
||||
return imageList;
|
||||
#else
|
||||
Q_UNUSED(resolution);
|
||||
return QVector<QImage>();
|
||||
#endif
|
||||
}
|
||||
|
||||
QImage PDFDocument::getPrintableImage(int pageNum, int resolution) const
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (pageNum < 0 || pageNum >= m_pages.size())
|
||||
Q_UNUSED(pageNum);
|
||||
Q_UNUSED(resolution);
|
||||
return QImage();
|
||||
return m_pages[pageNum]->getPrintableImage(resolution);
|
||||
#else
|
||||
Q_UNUSED(pageNum);
|
||||
Q_UNUSED(resolution);
|
||||
return QImage();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::ensureCurPageVisible(int xOfs, int yOfs)
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_currentPage >= m_ranges.size() || m_currentPage < 0)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
if (m_scrollArea->verticalScrollBar()->maximum() == 0)
|
||||
{
|
||||
QTimer::singleShot(50, this, [this, xOfs, yOfs]() { ensureCurPageVisible(xOfs, yOfs); });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int y = m_ranges.at(m_currentPage) + yOfs;
|
||||
|
||||
y -= m_pdfLabel->layout()->spacing() * 2;
|
||||
|
||||
int x = m_scrollArea->horizontalScrollBar()->value() + xOfs;
|
||||
|
||||
|
||||
m_scrollArea->ensureVisible(x, y, 0, 0);
|
||||
y += m_scrollArea->height();
|
||||
|
||||
m_scrollArea->ensureVisible(x, y, 0, 0);
|
||||
#else
|
||||
Q_UNUSED(xOfs);
|
||||
Q_UNUSED(yOfs);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::rebuildRanges()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
QVBoxLayout *l = qobject_cast<QVBoxLayout *> (m_pdfLabel->layout());
|
||||
m_ranges.clear();
|
||||
int height = l->contentsMargins().top();
|
||||
for (PDFPage *p : std::as_const(m_pages))
|
||||
void PDFDocument::ensureCurPageVisible(int xOfs, int yOfs)
|
||||
{
|
||||
m_ranges += height;
|
||||
height += p->height();
|
||||
height += l->spacing();
|
||||
}
|
||||
m_pdfLabel->resize(m_pdfLabel->sizeHint());
|
||||
m_pdfLabel->setMinimumSize(m_pdfLabel->sizeHint());
|
||||
#else
|
||||
// Stub implementation when Poppler not available
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_currentPage >= m_ranges.size() || m_currentPage < 0)
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (m_scrollArea->verticalScrollBar()->maximum() == 0)
|
||||
{
|
||||
QTimer::singleShot(50, this, [this, xOfs, yOfs]() { ensureCurPageVisible(xOfs, yOfs); });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int y = m_ranges.at(m_currentPage) + yOfs;
|
||||
|
||||
y -= m_pdfLabel->layout()->spacing() * 2;
|
||||
|
||||
int x = m_scrollArea->horizontalScrollBar()->value() + xOfs;
|
||||
|
||||
|
||||
m_scrollArea->ensureVisible(x, y, 0, 0);
|
||||
y += m_scrollArea->height();
|
||||
|
||||
m_scrollArea->ensureVisible(x, y, 0, 0);
|
||||
#else
|
||||
Q_UNUSED(xOfs);
|
||||
Q_UNUSED(yOfs);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::rebuildRanges()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
QVBoxLayout *l = qobject_cast<QVBoxLayout *>(m_pdfLabel->layout());
|
||||
m_ranges.clear();
|
||||
int height = l->contentsMargins().top();
|
||||
for (PDFPage *p : std::as_const(m_pages))
|
||||
{
|
||||
m_ranges += height;
|
||||
height += p->height();
|
||||
height += l->spacing();
|
||||
}
|
||||
m_pdfLabel->resize(m_pdfLabel->sizeHint());
|
||||
m_pdfLabel->setMinimumSize(m_pdfLabel->sizeHint());
|
||||
#else
|
||||
// Stub implementation when Poppler not available
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+57
-63
@@ -13,8 +13,8 @@
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
namespace Poppler
|
||||
{
|
||||
class Document;
|
||||
class LinkDestination;
|
||||
class Document;
|
||||
class LinkDestination;
|
||||
}
|
||||
#endif
|
||||
class QUrl;
|
||||
@@ -22,102 +22,96 @@ class QScrollArea;
|
||||
namespace NGL
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
class PDFPage;
|
||||
class PDFPage;
|
||||
#endif
|
||||
|
||||
|
||||
class NGLWIDGETS_EXPORT PDFDocument : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
class NGLWIDGETS_EXPORT PDFDocument : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PDFDocument(QWidget *parent = nullptr);
|
||||
|
||||
explicit PDFDocument(QWidget *parent = nullptr);
|
||||
|
||||
|
||||
virtual ~PDFDocument();
|
||||
virtual ~PDFDocument();
|
||||
|
||||
|
||||
|
||||
int curPage() const;
|
||||
|
||||
int curPage() const;
|
||||
|
||||
int numPages() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
int numPages() const;
|
||||
|
||||
bool showPDF(const QString &path);
|
||||
public Q_SLOTS:
|
||||
|
||||
|
||||
|
||||
bool showPDF(const QUrl &url);
|
||||
bool showPDF(const QString &path);
|
||||
|
||||
|
||||
|
||||
bool showPDF(const QByteArray &pdf);
|
||||
bool showPDF(const QUrl &url);
|
||||
|
||||
|
||||
|
||||
void setZoomFactor(double zoom);
|
||||
bool showPDF(const QByteArray &pdf);
|
||||
|
||||
|
||||
void setZoomFactor(double zoom);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
void setRotation(Poppler::Page::Rotation rot);
|
||||
void setRotation(Poppler::Page::Rotation rot);
|
||||
#endif
|
||||
|
||||
bool setPage(int page);
|
||||
|
||||
bool setPage(int page);
|
||||
|
||||
bool nextPage();
|
||||
|
||||
|
||||
bool previousPage();
|
||||
bool nextPage();
|
||||
|
||||
void resizePdfToWidth();
|
||||
|
||||
public:
|
||||
bool previousPage();
|
||||
|
||||
void resizePdfToWidth();
|
||||
|
||||
public:
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
Poppler::Page::Rotation getRotation() const { return m_rotation; }
|
||||
Poppler::Page::Rotation getRotation() const { return m_rotation; }
|
||||
#endif
|
||||
|
||||
QVector<QImage> getPrintableImages(int resolution = 300) const;
|
||||
|
||||
QVector<QImage> getPrintableImages(int resolution = 300) const;
|
||||
|
||||
QImage getPrintableImage(int pageNum, int resolution = 300) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
void currentPageChanged(int cur, int max);
|
||||
QImage getPrintableImage(int pageNum, int resolution = 300) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
void currentPageChanged(int cur, int max);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
void rotationChanged(Poppler::Page::Rotation rot);
|
||||
void linkClicked(const QString &url);
|
||||
void rotationChanged(Poppler::Page::Rotation rot);
|
||||
void linkClicked(const QString &url);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onLinkClicked(const Poppler::LinkDestination &dest);
|
||||
protected Q_SLOTS:
|
||||
void onLinkClicked(const Poppler::LinkDestination &dest);
|
||||
#endif
|
||||
void onVSliderValueChanged(int y);
|
||||
void onPageRendered();
|
||||
void onVSliderValueChanged(int y);
|
||||
void onPageRendered();
|
||||
|
||||
protected:
|
||||
bool showPDFInternal();
|
||||
void ensureCurPageVisible(int xOfs = 0, int yOfs = 0);
|
||||
void rebuildRanges();
|
||||
protected:
|
||||
bool showPDFInternal();
|
||||
void ensureCurPageVisible(int xOfs = 0, int yOfs = 0);
|
||||
void rebuildRanges();
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
std::unique_ptr<Poppler::Document> m_doc;
|
||||
std::unique_ptr<Poppler::Document> m_doc;
|
||||
#endif
|
||||
int m_currentPage;
|
||||
int m_maxCachedPages;
|
||||
double m_scaleFactor;
|
||||
double m_widthFactor;
|
||||
QString m_currentPath;
|
||||
int m_currentPage;
|
||||
int m_maxCachedPages;
|
||||
double m_scaleFactor;
|
||||
double m_widthFactor;
|
||||
QString m_currentPath;
|
||||
|
||||
QWidget *m_pdfLabel;
|
||||
QScrollArea *m_scrollArea;
|
||||
QWidget *m_pdfLabel;
|
||||
QScrollArea *m_scrollArea;
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
QVector<PDFPage *> m_pages;
|
||||
QVector<int> m_ranges;
|
||||
QVector<QPointer<PDFPage> > m_renderedPages;
|
||||
Poppler::Page::Rotation m_rotation;
|
||||
QVector<PDFPage *> m_pages;
|
||||
QVector<int> m_ranges;
|
||||
QVector<QPointer<PDFPage>> m_renderedPages;
|
||||
Poppler::Page::Rotation m_rotation;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
Executable → Regular
+183
-185
@@ -11,207 +11,205 @@
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
template <typename T>
|
||||
static inline T getRotatedSize(const T &in, Poppler::Page::Rotation rot)
|
||||
{
|
||||
switch (rot)
|
||||
template <typename T> static inline T getRotatedSize(const T &in, Poppler::Page::Rotation rot)
|
||||
{
|
||||
case Poppler::Page::Rotate0:
|
||||
case Poppler::Page::Rotate180:
|
||||
return in;
|
||||
case Poppler::Page::Rotate90:
|
||||
case Poppler::Page::Rotate270:
|
||||
return in.transposed();
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return in;
|
||||
}
|
||||
|
||||
PDFPage::PDFPage(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_page(nullptr)
|
||||
, m_rotation(Poppler::Page::Rotate0)
|
||||
, m_scaleFactor(1.0)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
PDFPage::~PDFPage()
|
||||
{
|
||||
delete m_page;
|
||||
}
|
||||
|
||||
void PDFPage::setPopplerPage(Poppler::Page *page)
|
||||
{
|
||||
if (m_page == page)
|
||||
return;
|
||||
delete m_page;
|
||||
m_page = page;
|
||||
m_links.clear();
|
||||
m_linkRects.clear();
|
||||
if (!m_page)
|
||||
return;
|
||||
|
||||
// Poppler::Page::links() returns std::vector<std::unique_ptr<Poppler::Link>> in Poppler Qt6
|
||||
auto links = m_page->links();
|
||||
for (auto &linkUp : links)
|
||||
{
|
||||
Poppler::Link *link = linkUp.get();
|
||||
if (!link)
|
||||
continue;
|
||||
if (link->linkType() == Poppler::Link::Browse ||
|
||||
link->linkType() == Poppler::Link::Goto)
|
||||
m_links.emplace_back(std::move(linkUp));
|
||||
else
|
||||
std::cerr << "linktype: " << link->linkType() << std::endl;
|
||||
}
|
||||
|
||||
rebuildInternalData();
|
||||
}
|
||||
|
||||
void PDFPage::setZoomFactor(double zoom)
|
||||
{
|
||||
if (qFuzzyCompare(m_scaleFactor, zoom))
|
||||
return;
|
||||
m_scaleFactor = zoom;
|
||||
rebuildInternalData();
|
||||
}
|
||||
|
||||
void PDFPage::setRotation(Poppler::Page::Rotation rot)
|
||||
{
|
||||
if (m_rotation == rot)
|
||||
return;
|
||||
m_rotation = rot;
|
||||
rebuildInternalData();
|
||||
}
|
||||
|
||||
void PDFPage::clearPixmap()
|
||||
{
|
||||
m_pdfPixmap = QPixmap();
|
||||
}
|
||||
|
||||
QImage PDFPage::getPrintableImage(int resolution) const
|
||||
{
|
||||
if (!m_page)
|
||||
return QImage();
|
||||
|
||||
|
||||
Poppler::Page::Rotation rot = Poppler::Page::Rotate0;
|
||||
|
||||
if (m_page->orientation() == Poppler::Page::Landscape)
|
||||
rot = Poppler::Page::Rotate270;
|
||||
else if (m_page->orientation() == Poppler::Page::Seascape)
|
||||
rot = Poppler::Page::Rotate90;
|
||||
else if (m_page->orientation() == Poppler::Page::UpsideDown)
|
||||
rot = Poppler::Page::Rotate180;
|
||||
Q_UNUSED(rot)
|
||||
|
||||
|
||||
return m_page->renderToImage(resolution, resolution, -1, -1, -1, -1, m_rotation);
|
||||
}
|
||||
|
||||
QSize PDFPage::sizeHint() const
|
||||
{
|
||||
if (!m_page)
|
||||
return QSize();
|
||||
return getRotatedSize(m_page->pageSize(), m_rotation);
|
||||
}
|
||||
|
||||
void PDFPage::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (!m_page)
|
||||
return;
|
||||
if (m_pdfPixmap.isNull())
|
||||
{
|
||||
const QImage img = m_page->renderToImage(m_scaleFactor * 72, m_scaleFactor * 72, -1, -1, -1, -1, m_rotation);
|
||||
m_pdfPixmap = QPixmap::fromImage(img);
|
||||
emit pageRendered();
|
||||
}
|
||||
QPainter p(this);
|
||||
p.drawPixmap(0, 0, m_pdfPixmap);
|
||||
p.end();
|
||||
}
|
||||
|
||||
void PDFPage::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
const QPointF pos = event->position();
|
||||
for (const auto &linkRect : std::as_const(m_linkRects))
|
||||
{
|
||||
if (linkRect.contains(pos))
|
||||
switch (rot)
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
return;
|
||||
case Poppler::Page::Rotate0:
|
||||
case Poppler::Page::Rotate180:
|
||||
return in;
|
||||
case Poppler::Page::Rotate90:
|
||||
case Poppler::Page::Rotate270:
|
||||
return in.transposed();
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return in;
|
||||
}
|
||||
setCursor(Qt::ArrowCursor);
|
||||
QWidget::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void PDFPage::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
const QPointF pos = event->position();
|
||||
for (int i = 0; i < m_linkRects.size(); ++i)
|
||||
PDFPage::PDFPage(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_page(nullptr)
|
||||
, m_rotation(Poppler::Page::Rotate0)
|
||||
, m_scaleFactor(1.0)
|
||||
{
|
||||
if (m_linkRects.at(i).contains(pos))
|
||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
PDFPage::~PDFPage()
|
||||
{
|
||||
delete m_page;
|
||||
}
|
||||
|
||||
void PDFPage::setPopplerPage(Poppler::Page *page)
|
||||
{
|
||||
if (m_page == page)
|
||||
return;
|
||||
delete m_page;
|
||||
m_page = page;
|
||||
m_links.clear();
|
||||
m_linkRects.clear();
|
||||
if (!m_page)
|
||||
return;
|
||||
|
||||
// Poppler::Page::links() returns std::vector<std::unique_ptr<Poppler::Link>> in Poppler Qt6
|
||||
auto links = m_page->links();
|
||||
for (auto &linkUp : links)
|
||||
{
|
||||
const Poppler::Link *link = m_links.at(i).get();
|
||||
Poppler::Link *link = linkUp.get();
|
||||
if (!link)
|
||||
continue;
|
||||
if (link->linkType() == Poppler::Link::Browse)
|
||||
if (link->linkType() == Poppler::Link::Browse || link->linkType() == Poppler::Link::Goto)
|
||||
m_links.emplace_back(std::move(linkUp));
|
||||
else
|
||||
std::cerr << "linktype: " << link->linkType() << std::endl;
|
||||
}
|
||||
|
||||
rebuildInternalData();
|
||||
}
|
||||
|
||||
void PDFPage::setZoomFactor(double zoom)
|
||||
{
|
||||
if (qFuzzyCompare(m_scaleFactor, zoom))
|
||||
return;
|
||||
m_scaleFactor = zoom;
|
||||
rebuildInternalData();
|
||||
}
|
||||
|
||||
void PDFPage::setRotation(Poppler::Page::Rotation rot)
|
||||
{
|
||||
if (m_rotation == rot)
|
||||
return;
|
||||
m_rotation = rot;
|
||||
rebuildInternalData();
|
||||
}
|
||||
|
||||
void PDFPage::clearPixmap()
|
||||
{
|
||||
m_pdfPixmap = QPixmap();
|
||||
}
|
||||
|
||||
QImage PDFPage::getPrintableImage(int resolution) const
|
||||
{
|
||||
if (!m_page)
|
||||
return QImage();
|
||||
|
||||
|
||||
Poppler::Page::Rotation rot = Poppler::Page::Rotate0;
|
||||
|
||||
if (m_page->orientation() == Poppler::Page::Landscape)
|
||||
rot = Poppler::Page::Rotate270;
|
||||
else if (m_page->orientation() == Poppler::Page::Seascape)
|
||||
rot = Poppler::Page::Rotate90;
|
||||
else if (m_page->orientation() == Poppler::Page::UpsideDown)
|
||||
rot = Poppler::Page::Rotate180;
|
||||
Q_UNUSED(rot)
|
||||
|
||||
|
||||
return m_page->renderToImage(resolution, resolution, -1, -1, -1, -1, m_rotation);
|
||||
}
|
||||
|
||||
QSize PDFPage::sizeHint() const
|
||||
{
|
||||
if (!m_page)
|
||||
return QSize();
|
||||
return getRotatedSize(m_page->pageSize(), m_rotation);
|
||||
}
|
||||
|
||||
void PDFPage::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (!m_page)
|
||||
return;
|
||||
if (m_pdfPixmap.isNull())
|
||||
{
|
||||
const QImage img = m_page->renderToImage(m_scaleFactor * 72, m_scaleFactor * 72, -1, -1, -1, -1, m_rotation);
|
||||
m_pdfPixmap = QPixmap::fromImage(img);
|
||||
emit pageRendered();
|
||||
}
|
||||
QPainter p(this);
|
||||
p.drawPixmap(0, 0, m_pdfPixmap);
|
||||
p.end();
|
||||
}
|
||||
|
||||
void PDFPage::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
const QPointF pos = event->position();
|
||||
for (const auto &linkRect : std::as_const(m_linkRects))
|
||||
{
|
||||
if (linkRect.contains(pos))
|
||||
{
|
||||
const Poppler::LinkBrowse *linkBrowse = static_cast<const Poppler::LinkBrowse *>(link);
|
||||
emit externalLinkClicked(linkBrowse->url());
|
||||
return;
|
||||
}
|
||||
else if (link->linkType() == Poppler::Link::Goto)
|
||||
{
|
||||
const Poppler::LinkGoto *linkGoto = static_cast<const Poppler::LinkGoto *>(link);
|
||||
if (linkGoto->isExternal())
|
||||
{
|
||||
const QUrl url = QUrl::fromLocalFile(linkGoto->fileName());
|
||||
emit externalLinkClicked(url.toString());
|
||||
return;
|
||||
}
|
||||
emit linkClicked(linkGoto->destination());
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
setCursor(Qt::ArrowCursor);
|
||||
QWidget::mouseMoveEvent(event);
|
||||
}
|
||||
QWidget::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void PDFPage::rebuildInternalData()
|
||||
{
|
||||
clearPixmap();
|
||||
|
||||
if (!m_page)
|
||||
return;
|
||||
|
||||
const QSizeF s(rotatedPageSize());
|
||||
const int w = qRound(s.width() * m_scaleFactor);
|
||||
const int h = qRound(s.height() * m_scaleFactor);
|
||||
setMinimumSize(w, h);
|
||||
resize(sizeHint());
|
||||
|
||||
|
||||
m_linkRects.clear();
|
||||
m_linkRects.reserve(static_cast<int>(m_links.size()));
|
||||
for (const auto &linkUp : m_links)
|
||||
void PDFPage::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
const Poppler::Link *link = linkUp.get();
|
||||
if (!link)
|
||||
continue;
|
||||
const QRectF r = link->linkArea();
|
||||
m_linkRects += QRectF(r.x() * w, r.y() * h, r.width() * w, r.height() * h);
|
||||
const QPointF pos = event->position();
|
||||
for (int i = 0; i < m_linkRects.size(); ++i)
|
||||
{
|
||||
if (m_linkRects.at(i).contains(pos))
|
||||
{
|
||||
const Poppler::Link *link = m_links.at(i).get();
|
||||
if (!link)
|
||||
continue;
|
||||
if (link->linkType() == Poppler::Link::Browse)
|
||||
{
|
||||
const Poppler::LinkBrowse *linkBrowse = static_cast<const Poppler::LinkBrowse *>(link);
|
||||
emit externalLinkClicked(linkBrowse->url());
|
||||
return;
|
||||
}
|
||||
else if (link->linkType() == Poppler::Link::Goto)
|
||||
{
|
||||
const Poppler::LinkGoto *linkGoto = static_cast<const Poppler::LinkGoto *>(link);
|
||||
if (linkGoto->isExternal())
|
||||
{
|
||||
const QUrl url = QUrl::fromLocalFile(linkGoto->fileName());
|
||||
emit externalLinkClicked(url.toString());
|
||||
return;
|
||||
}
|
||||
emit linkClicked(linkGoto->destination());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
QWidget::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void PDFPage::rebuildInternalData()
|
||||
{
|
||||
clearPixmap();
|
||||
|
||||
if (!m_page)
|
||||
return;
|
||||
|
||||
const QSizeF s(rotatedPageSize());
|
||||
const int w = qRound(s.width() * m_scaleFactor);
|
||||
const int h = qRound(s.height() * m_scaleFactor);
|
||||
setMinimumSize(w, h);
|
||||
resize(sizeHint());
|
||||
|
||||
|
||||
m_linkRects.clear();
|
||||
m_linkRects.reserve(static_cast<int>(m_links.size()));
|
||||
for (const auto &linkUp : m_links)
|
||||
{
|
||||
const Poppler::Link *link = linkUp.get();
|
||||
if (!link)
|
||||
continue;
|
||||
const QRectF r = link->linkArea();
|
||||
m_linkRects += QRectF(r.x() * w, r.y() * h, r.width() * w, r.height() * h);
|
||||
}
|
||||
}
|
||||
|
||||
QSizeF PDFPage::rotatedPageSize() const
|
||||
{
|
||||
return m_page ? getRotatedSize(m_page->pageSizeF(), m_rotation) : QSizeF();
|
||||
}
|
||||
}
|
||||
|
||||
QSizeF PDFPage::rotatedPageSize() const
|
||||
{
|
||||
return m_page ? getRotatedSize(m_page->pageSizeF(), m_rotation) : QSizeF();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_POPPLER_QT6
|
||||
#endif // HAVE_POPPLER_QT6
|
||||
Executable → Regular
+41
-39
@@ -12,9 +12,9 @@
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
namespace Poppler
|
||||
{
|
||||
class Page;
|
||||
class Link;
|
||||
class LinkDestination;
|
||||
class Page;
|
||||
class Link;
|
||||
class LinkDestination;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -22,44 +22,46 @@ namespace NGL
|
||||
{
|
||||
|
||||
|
||||
class PDFPage final : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PDFPage(QWidget *parent = nullptr);
|
||||
virtual ~PDFPage();
|
||||
class PDFPage final : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PDFPage(QWidget *parent = nullptr);
|
||||
virtual ~PDFPage();
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
void setPopplerPage(Poppler::Page *page);
|
||||
void setRotation(Poppler::Page::Rotation rot);
|
||||
QImage getPrintableImage(int resolution = 300) const;
|
||||
Q_SIGNALS:
|
||||
void linkClicked(const Poppler::LinkDestination &dest);
|
||||
void setPopplerPage(Poppler::Page *page);
|
||||
void setRotation(Poppler::Page::Rotation rot);
|
||||
QImage getPrintableImage(int resolution = 300) const;
|
||||
Q_SIGNALS:
|
||||
void linkClicked(const Poppler::LinkDestination &dest);
|
||||
#endif
|
||||
public:
|
||||
void setZoomFactor(double zoom);
|
||||
void clearPixmap();
|
||||
QSize sizeHint() const override;
|
||||
Q_SIGNALS:
|
||||
void pageRendered();
|
||||
|
||||
void externalLinkClicked(const QString &url);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
private:
|
||||
void rebuildInternalData();
|
||||
QSizeF rotatedPageSize() const;
|
||||
protected:
|
||||
public:
|
||||
void setZoomFactor(double zoom);
|
||||
void clearPixmap();
|
||||
QSize sizeHint() const override;
|
||||
Q_SIGNALS:
|
||||
void pageRendered();
|
||||
|
||||
void externalLinkClicked(const QString &url);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
void rebuildInternalData();
|
||||
QSizeF rotatedPageSize() const;
|
||||
|
||||
protected:
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
Poppler::Page *m_page;
|
||||
std::vector<std::unique_ptr<Poppler::Link>> m_links;
|
||||
QList< QRectF > m_linkRects;
|
||||
Poppler::Page::Rotation m_rotation;
|
||||
Poppler::Page *m_page;
|
||||
std::vector<std::unique_ptr<Poppler::Link>> m_links;
|
||||
QList<QRectF> m_linkRects;
|
||||
Poppler::Page::Rotation m_rotation;
|
||||
#endif
|
||||
double m_scaleFactor;
|
||||
QPixmap m_pdfPixmap;
|
||||
};
|
||||
}
|
||||
double m_scaleFactor;
|
||||
QPixmap m_pdfPixmap;
|
||||
};
|
||||
}
|
||||
Loaded 100 of 387 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user