31#include "KDbConnection.h"
32#include "KDbDriverManager.h"
33#include "KDbUtils_p.h"
34#include "config-kdb.h"
37#include <QRegularExpression>
43static const int SQUEEZED_TEXT_LIMIT = 1024;
44static const int SQUEEZED_TEXT_SUFFIX = 24;
53#define interface struct
57using namespace KDbUtils;
62 Private() : isNull(true) {}
63 Private(
const QVariant &aValue,
const QString &aCaption)
64 : value(aValue), caption(aCaption), isNull(false)
68 return std::tie(value, caption, isNull) == std::tie(other.value, other.caption, other.isNull);
81 : d(new Private(value, caption))
86: d(new Private(*other.d))
97 return *d == *other.d;
110void Property::setValue(
const QVariant &value)
116QString Property::caption()
const
121void Property::setCaption(
const QString &caption)
123 d->caption = caption;
134 while (o && o != par) {
140QString KDbUtils::toISODateStringWithMs(
const QTime& time)
142#ifdef HAVE_QT_ISODATEWITHMS
156#ifdef HAVE_QT_ISODATEWITHMS
167 QString timeString = KDbUtils::toISODateStringWithMs(dateTime.
time());
171 const int offset = strlen(
"0000-00-00T");
172 const int timeLen = strlen(
"00:00:00");
173 result.
replace(offset, timeLen, timeString);
178QTime KDbUtils::timeFromISODateStringWithMs(
const QString &
string)
180#ifdef HAVE_QT_ISODATEWITHMS
189#ifdef HAVE_QT_ISODATEWITHMS
201 return QDateTime(
QDate(0, 1, 2), KDbUtils::timeFromISODateStringWithMs(s));
223 kdbDebug() << array[3] << array[4] << array[5];
224 const int size = array.
size();
226 string->reserve(size);
227 for (
int i = 0; i < size; i++) {
228 (*string)[i] =
QChar(ushort(array[i]) + 1);
245 const int size =
string.
length();
247 for (
int i = 0; i < size; i++) {
248 array[i] = char(
string[i].unicode() - 1);
265 return _string.simplified();
268void KDbUtils::simpleCrypt(
QString *
string)
273 for (
int i = 0; i <
string->length(); i++) {
274 ushort& unicode = (*string)[i].unicode();
279bool KDbUtils::simpleDecrypt(
QString *
string)
285 for (
int i = 0; i < result.
length(); i++) {
286 ushort& unicode = result[i].
unicode();
287 if (unicode <= (47 + i)) {
296QString KDbUtils::pointerToStringInternal(
void* pointer,
int size)
299 unsigned char* cstr_pointer = (
unsigned char*) & pointer;
300 for (
int i = 0; i < size; i++) {
302 s.
asprintf(
"%2.2x", cstr_pointer[i]);
308void* KDbUtils::stringToPointerInternal(
const QString&
string,
int size)
310 if ((
string.length() / 2) < size)
315 for (
int i = 0; i < size; i++) {
316 array[i] = (
unsigned char)(
string.midRef(i * 2, 2).toUInt(&ok, 16));
320 return static_cast<void*
>(array.
data());
329 Private() : array(nullptr), set(nullptr) {}
333 const char*
const * array;
334 QSet<QByteArray> *set;
337StaticSetOfStrings::StaticSetOfStrings()
342StaticSetOfStrings::StaticSetOfStrings(
const char*
const array[])
348StaticSetOfStrings::~StaticSetOfStrings()
353void StaticSetOfStrings::setStrings(
const char*
const array[])
360bool StaticSetOfStrings::isEmpty()
const
362 return d->array ==
nullptr;
369 for (
const char *
const * p = d->array;*p;p++)
372 return d->set->contains(
string);
392 if ( ignore || (_stat.st_mode & S_IXUSR) ) {
393 if ( ((_stat.st_mode & S_IFMT) == S_IFREG) || ((_stat.st_mode & S_IFMT) == S_IFLNK) ) {
403static QString checkExecutable(
const QString& path,
bool ignoreExecBit)
406 QString bundle = getBundle(path, ignoreExecBit);
411 QFileInfo info(path);
412 QFileInfo orig = info;
421 if ( ignoreExecBit || (_stat.st_mode & S_IXUSR) ) {
422 if ( ((_stat.st_mode & S_IFMT) == S_IFREG) || ((_stat.st_mode & S_IFMT) == S_IFLNK) ) {
444#if defined _WIN32 || defined _WIN64
445# define KPATH_SEPARATOR ';'
448# define KPATH_SEPARATOR ':'
453static inline QString equalizePath(QString &str)
460 return f.absoluteFilePath();
467static void tokenize(QStringList& tokens,
const QString& str,
468 const QString& delim)
470 const int len = str.
length();
473 for(
int index = 0; index < len; index++) {
475 tokens.
append(equalizePath(token));
482 tokens.
append(equalizePath(token));
489 if (!fname.
isEmpty() && fname[0] == QLatin1Char(
'~')) {
490 int pos = fname.
indexOf( QLatin1Char(
'/') );
493 ret += fname.midRef(pos);
496 }
else if (fname.
length() > 1 && fname[0] == QLatin1Char(ESCAPE) && fname[1] == QLatin1Char(
'~')) {
503static QStringList systemPaths(
const QString& pstr)
512 QString delimiters(QLatin1Char(KPATH_SEPARATOR));
513 delimiters += QLatin1Char(
'\b');
514 tokenize(tokens, p, delimiters);
516 QStringList exePaths;
519 for(
int i = 0; i < tokens.
count(); i++) {
527static QStringList executableExtensions()
533 ret << QLatin1String(
".exe")
534 << QLatin1String(
".com")
535 << QLatin1String(
".bat")
536 << QLatin1String(
".cmd");
543QString KDbUtils::findExe(
const QString& appname,
545 FindExeOptions options)
548 QStringList executable_extensions = executableExtensions();
549 if (!executable_extensions.
contains(
554 foreach (
const QString& extension, executable_extensions) {
555 found_exe = findExe(appname + extension, path, options);
566 return checkExecutable(appname, options & FindExeOption::IgnoreExecBit);
572 const QStringList exePaths = systemPaths(path);
575 p = (*it) + QLatin1Char(
'/');
579 result = checkExecutable(p, options & FindExeOption::IgnoreExecBit);
588 result = checkExecutable(p, options & FindExeOption::IgnoreExecBit);
604 Private(
const Private &other) {
607 void copy(
const Private &other) {
608 for (AutodeletedHash<QByteArray, Property*>::ConstIterator it(other.data.constBegin());
609 it != other.data.constEnd(); ++it)
611 data.insert(it.key(),
new Property(*it.value()));
615 if (data.count() != other.data.count()) {
618 for (AutodeletedHash<QByteArray, Property*>::ConstIterator it(other.data.constBegin());
619 it != other.data.constEnd(); ++it)
621 AutodeletedHash<QByteArray, Property*>::ConstIterator findHere(data.constFind(it.key()));
622 if (*findHere.value() != *it.value()) {
628 AutodeletedHash<QByteArray, Property*> data;
631PropertySet::PropertySet()
637 : d(new Private(*other.d))
641PropertySet::~PropertySet()
648 if (
this != &other) {
657 return *d == *other.d;
663 Property *existing = d->data.value(name);
665 existing->setValue(value);
667 existing->setCaption(caption);
671 d->data.insert(name,
new Property(value, realCaption));
673 kdbWarning() << name <<
"cannot be used as property name";
680 Property *existing = d->data.value(name);
682 existing->setCaption(caption);
688 Property *existing = d->data.value(name);
690 existing->setValue(value);
696 d->
data.remove(name);
702 return result ? *result :
Property();
707 return d->
data.keys();
712 switch(value.
type()) {
void setValue(const QByteArray &name, const QVariant &value)
Sets value for property name to value.
Property property(const QByteArray &name) const
void remove(const QByteArray &name)
Removes property with a given name.
PropertySet & operator=(const PropertySet &other)
Assigns other to this property set and returns a reference to this property set.
void setCaption(const QByteArray &name, const QString &caption)
Sets caption for property name to caption.
void insert(const QByteArray &name, const QVariant &value, const QString &caption=QString())
Inserts property with a given name, value and caption.
QList< QByteArray > names() const
bool operator==(const PropertySet &other) const
A set created from static (0-terminated) array of raw null-terminated strings.
bool contains(const QByteArray &string) const
virtual bool isNull() const=0
bool operator==(const Resource &other) const
KDB_EXPORT bool isIdentifier(const QString &s)
KIOCORE_EXPORT bool operator==(const UDSEntry &entry, const UDSEntry &other)
KIOCORE_EXPORT StatJob * stat(const QUrl &url, JobFlags flags=DefaultFlags)
KCOREADDONS_EXPORT QString tildeExpand(const QString &path)
QAction * copy(const QObject *recvr, const char *slot, QObject *parent)
const char * constData() const const
QByteArray fromRawData(const char *data, qsizetype size)
QByteArray left(qsizetype len) const const
qsizetype length() const const
QByteArray number(double n, char format, int precision)
void resize(qsizetype newSize, char c)
QByteArray right(qsizetype len) const const
qsizetype size() const const
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
bool isValid() const const
QString toString(QStringView format, QCalendar cal) const const
QString decodeName(const QByteArray &localFileName)
QString absoluteFilePath() const const
QString canonicalFilePath() const const
bool exists(const QString &path)
QString filePath() const const
bool isExecutable() const const
bool isFile() const const
bool isSymLink() const const
void setFile(const QDir &dir, const QString &path)
void append(QList< T > &&value)
qsizetype count() const const
QObject * parent() const const
QString & append(QChar ch)
QString asprintf(const char *cformat,...)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString fromLatin1(QByteArrayView str)
QString fromLocal8Bit(QByteArrayView str)
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
bool isNull() const const
QString left(qsizetype n) const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString right(qsizetype n) const const
QString section(QChar sep, qsizetype start, qsizetype end, SectionFlags flags) const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QByteArray toUtf8() const const
const QChar * unicode() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QTime fromString(QStringView string, QStringView format)
bool isValid(int h, int m, int s, int ms)
QString toString(QStringView format) const const
QByteArray toByteArray() const const
QString toString() const const