diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/common.pri | 24 | ||||
-rw-r--r-- | src/common/jsondb-error.h | 42 | ||||
-rw-r--r-- | src/common/jsondb-global.h | 42 | ||||
-rw-r--r-- | src/common/jsondb-strings.cpp | 115 | ||||
-rw-r--r-- | src/common/jsondb-strings.h | 42 | ||||
-rw-r--r-- | src/common/jsondbcollator.cpp | 341 | ||||
-rw-r--r-- | src/common/jsondbcollator.h | 173 | ||||
-rw-r--r-- | src/common/jsondbcollator_p.h | 87 | ||||
-rw-r--r-- | src/common/jsonstream.cpp | 141 | ||||
-rw-r--r-- | src/common/jsonstream.h | 89 |
10 files changed, 0 insertions, 1096 deletions
diff --git a/src/common/common.pri b/src/common/common.pri deleted file mode 100644 index 01e012c..0000000 --- a/src/common/common.pri +++ /dev/null @@ -1,24 +0,0 @@ -INCLUDEPATH += $$PWD - -include(../3rdparty/qjson/qjson.pri) - -unix { - contains(QT_CONFIG,icu) { - LIBS += -licuuc -licui18n - } else { - DEFINES += NO_COLLATION_SUPPORT - } -} - -HEADERS += \ - $$PWD/jsondb-global.h \ - $$PWD/jsondb-error.h \ - $$PWD/jsondb-strings.h \ - $$PWD/jsondbcollator.h \ - $$PWD/jsondbcollator_p.h \ - $$PWD/jsonstream.h - -SOURCES += \ - $$PWD/jsondb-strings.cpp \ - $$PWD/jsondbcollator.cpp \ - $$PWD/jsonstream.cpp diff --git a/src/common/jsondb-error.h b/src/common/jsondb-error.h deleted file mode 100644 index 3a4989e..0000000 --- a/src/common/jsondb-error.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "../clientcompat/jsondb-error.h" diff --git a/src/common/jsondb-global.h b/src/common/jsondb-global.h deleted file mode 100644 index 1ad585a..0000000 --- a/src/common/jsondb-global.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "../clientcompat/jsondb-global.h" diff --git a/src/common/jsondb-strings.cpp b/src/common/jsondb-strings.cpp deleted file mode 100644 index fa4e424..0000000 --- a/src/common/jsondb-strings.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "jsondb-strings.h" - -QT_BEGIN_NAMESPACE_JSONDB - -const QString JsonDbString::kUuidStr = QString::fromLatin1("_uuid"); -const QString JsonDbString::kVersionStr = QString::fromLatin1("_version"); -const QString JsonDbString::kIdStr = QString::fromLatin1("id"); -const QString JsonDbString::kResultStr = QString::fromLatin1("result"); -const QString JsonDbString::kErrorStr = QString::fromLatin1("error"); -const QString JsonDbString::kFieldNameStr = QString::fromLatin1("fieldName"); -const QString JsonDbString::kCodeStr = QString::fromLatin1("code"); -const QString JsonDbString::kMessageStr = QString::fromLatin1("message"); -const QString JsonDbString::kNameStr = QString::fromLatin1("name"); -const QString JsonDbString::kCountStr = QString::fromLatin1("count"); -const QString JsonDbString::kCurrentStr = QString::fromLatin1("_current"); -const QString JsonDbString::kDomainStr = QString::fromLatin1("_domain"); -const QString JsonDbString::kOwnerStr = QString::fromLatin1("_owner"); -const QString JsonDbString::kTypeStr = QString::fromLatin1("_type"); -const QString JsonDbString::kTypesStr = QString::fromLatin1("types"); -const QString JsonDbString::kParentStr = QString::fromLatin1("_parent"); -const QString JsonDbString::kSchemaTypeStr = QString::fromLatin1("_schemaType"); - -const QString JsonDbString::kActionStr = QString::fromLatin1("action"); -const QString JsonDbString::kActionsStr = QString::fromLatin1("actions"); -const QString JsonDbString::kActiveStr = QString::fromLatin1("active"); -const QString JsonDbString::kAddIndexStr = QString::fromLatin1("addIndex"); -const QString JsonDbString::kCreateStr = QString::fromLatin1("create"); -const QString JsonDbString::kDropStr = QString::fromLatin1("drop"); -const QString JsonDbString::kConflictsStr = QString::fromLatin1("conflicts"); -const QString JsonDbString::kConnectStr = QString::fromLatin1("connect"); -const QString JsonDbString::kDataStr = QString::fromLatin1("data"); -const QString JsonDbString::kDeletedStr = QString::fromLatin1("_deleted"); -const QString JsonDbString::kDisconnectStr = QString::fromLatin1("disconnect"); -const QString JsonDbString::kExplanationStr = QString::fromLatin1("explanation"); -const QString JsonDbString::kFindStr = QString::fromLatin1("find"); -const QString JsonDbString::kLengthStr = QString::fromLatin1("length"); -const QString JsonDbString::kLimitStr = QString::fromLatin1("limit"); -const QString JsonDbString::kMapTypeStr = QString::fromLatin1("Map"); -const QString JsonDbString::kMetaStr = QString::fromLatin1("_meta"); -const QString JsonDbString::kNotifyStr = QString::fromLatin1("notify"); -const QString JsonDbString::kNotificationTypeStr = QString::fromLatin1("notification"); -const QString JsonDbString::kObjectStr = QString::fromLatin1("object"); -const QString JsonDbString::kOffsetStr = QString::fromLatin1("offset"); -const QString JsonDbString::kQueryStr = QString::fromLatin1("query"); -const QString JsonDbString::kReduceTypeStr = QString::fromLatin1("Reduce"); -const QString JsonDbString::kRemoveStr = QString::fromLatin1("remove"); -const QString JsonDbString::kSchemaStr = QString::fromLatin1("schema"); -const QString JsonDbString::kUpdateStr = QString::fromLatin1("update"); -const QString JsonDbString::kTokenStr = QString::fromLatin1("token"); -const QString JsonDbString::kFlushStr = QString::fromLatin1("flush"); -const QString JsonDbString::kSettingsStr = QString::fromLatin1("settings"); -const QString JsonDbString::kViewTypeStr = QString::fromLatin1("View"); -const QString JsonDbString::kChangesSinceStr = QString::fromLatin1("changesSince"); -const QString JsonDbString::kStateNumberStr = QString::fromLatin1("stateNumber"); -const QString JsonDbString::kCollapsedStr = QString::fromLatin1("collapsed"); -const QString JsonDbString::kCurrentStateNumberStr = QString::fromLatin1("currentStateNumber"); -const QString JsonDbString::kStartingStateNumberStr = QString::fromLatin1("startingStateNumber"); -const QString JsonDbString::kTombstoneStr = QString::fromLatin1("Tombstone"); -const QString JsonDbString::kPartitionTypeStr = QString::fromLatin1("Partition"); -const QString JsonDbString::kPartitionStr = QString::fromLatin1("partition"); -const QString JsonDbString::kLogStr = QString::fromLatin1("log"); -const QString JsonDbString::kPropertyNameStr = QString::fromLatin1("propertyName"); -const QString JsonDbString::kPropertyTypeStr = QString::fromLatin1("propertyType"); -const QString JsonDbString::kPropertyFunctionStr = QString::fromLatin1("propertyFunction"); -const QString JsonDbString::kObjectTypeStr = QString::fromLatin1("objectType"); -const QString JsonDbString::kDbidTypeStr = QString::fromLatin1("DatabaseId"); -const QString JsonDbString::kIndexTypeStr = QString::fromLatin1("Index"); -const QString JsonDbString::kLocaleStr = QString::fromLatin1("locale"); -const QString JsonDbString::kCollationStr = QString::fromLatin1("collation"); -const QString JsonDbString::kCaseSensitiveStr = QString::fromLatin1("caseSensitive"); -const QString JsonDbString::kCasePreferenceStr = QString::fromLatin1("casePreference"); -const QString JsonDbString::kDatabaseSchemaVersionStr = QString::fromLatin1("databaseSchemaVersion"); - -QT_END_NAMESPACE_JSONDB diff --git a/src/common/jsondb-strings.h b/src/common/jsondb-strings.h deleted file mode 100644 index dc0295b..0000000 --- a/src/common/jsondb-strings.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "../clientcompat/jsondb-strings_p.h" diff --git a/src/common/jsondbcollator.cpp b/src/common/jsondbcollator.cpp deleted file mode 100644 index 4fa45c4..0000000 --- a/src/common/jsondbcollator.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef NO_COLLATION_SUPPORT - -#include "jsondbcollator.h" -#include "jsondbcollator_p.h" - -#include <unicode/utypes.h> -#include <unicode/ucol.h> -#include <unicode/ustring.h> - -#include "qdebug.h" - -QT_BEGIN_NAMESPACE_JSONDB - -JsonDbCollatorPrivate::~JsonDbCollatorPrivate() -{ - if (collator) - ucol_close(collator); -} - -static const int collationStringsCount = 13; -static const char * const collationStrings[collationStringsCount] = { - "default", - "big5han", - "dict", - "direct", - "gb2312", - "phonebk", - "pinyin", - "phonetic", - "reformed", - "standard", - "stroke", - "trad", - "unihan" -}; - -JsonDbCollator::JsonDbCollator(const QLocale &locale, JsonDbCollator::Collation collation) - : d(new JsonDbCollatorPrivate) -{ - d->locale = locale; - if ((int)collation >= 0 && (int)collation < collationStringsCount) - d->collation = collation; - - init(); -} - -JsonDbCollator::JsonDbCollator(const JsonDbCollator &other) - : d(other.d) -{ - d->ref.ref(); -} - -JsonDbCollator::~JsonDbCollator() -{ - if (!d->ref.deref()) - delete d; -} - -JsonDbCollator &JsonDbCollator::operator=(const JsonDbCollator &other) -{ - if (this != &other) { - if (!d->ref.deref()) - delete d; - *d = *other.d; - d->ref.ref(); - } - return *this; -} - -void JsonDbCollator::setLocale(const QLocale &locale) -{ - if (d->ref.load() != 1) - detach(); - if (d->collator) - ucol_close(d->collator); - d->locale = locale; - - init(); -} - -QLocale JsonDbCollator::locale() const -{ - return d->locale; -} - -void JsonDbCollator::setCollation(JsonDbCollator::Collation collation) -{ - if ((int)collation < 0 || (int)collation >= collationStringsCount) - return; - - if (d->ref.load() != 1) - detach(); - if (d->collator) - ucol_close(d->collator); - d->collation = collation; - - init(); -} - -JsonDbCollator::Collation JsonDbCollator::collation() const -{ - return d->collation; -} - -void JsonDbCollator::init() -{ - Q_ASSERT((int)d->collation < collationStringsCount); - const char *collationString = collationStrings[(int)d->collation]; - UErrorCode status = U_ZERO_ERROR; - QByteArray name = (d->locale.bcp47Name().replace(QLatin1Char('-'), QLatin1Char('_')) + QLatin1String("@collation=") + QLatin1String(collationString)).toLatin1(); - d->collator = ucol_open(name.constData(), &status); - if (U_FAILURE(status)) - qWarning("Could not create collator: %d", status); - - // enable normalization by default - ucol_setAttribute(d->collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); - - // fetch options from the collator - d->options = 0; - - switch (ucol_getAttribute(d->collator, UCOL_CASE_FIRST, &status)) { - case UCOL_UPPER_FIRST: d->options |= JsonDbCollator::PreferUpperCase; break; - case UCOL_LOWER_FIRST: d->options |= JsonDbCollator::PreferLowerCase; break; - case UCOL_OFF: - default: - break; - } - - switch (ucol_getAttribute(d->collator, UCOL_FRENCH_COLLATION, &status)) { - case UCOL_ON: d->options |= JsonDbCollator::FrenchCollation; break; - case UCOL_OFF: - default: - break; - } - - switch (ucol_getAttribute(d->collator, UCOL_ALTERNATE_HANDLING, &status)) { - case UCOL_SHIFTED: d->options |= JsonDbCollator::IgnorePunctuation; break; - case UCOL_NON_IGNORABLE: - default: - break; - } - - - switch (ucol_getAttribute(d->collator, UCOL_CASE_LEVEL, &status)) { - case UCOL_ON: d->options |= JsonDbCollator::ExtraCaseLevel; break; - case UCOL_OFF: - default: - break; - } - - switch (ucol_getAttribute(d->collator, UCOL_HIRAGANA_QUATERNARY_MODE, &status)) { - case UCOL_ON: d->options |= JsonDbCollator::HiraganaQuaternaryMode; break; - case UCOL_OFF: - default: - break; - } - - switch (ucol_getAttribute(d->collator, UCOL_NUMERIC_COLLATION, &status)) { - case UCOL_ON: d->options |= JsonDbCollator::NumericMode; break; - case UCOL_OFF: - default: - break; - } -} - -void JsonDbCollator::detach() -{ - if (d->ref.load() != 1) { - JsonDbCollatorPrivate *x = new JsonDbCollatorPrivate; - x->ref.store(1); - x->strength = d->strength; - x->options = d->options; - x->modified = true; - x->collator = 0; - if (!d->ref.deref()) - delete d; - d = x; - } -} - -void JsonDbCollator::setStrength(JsonDbCollator::Strength strength) -{ - if (d->ref.load() != 1) - detach(); - - switch (strength) { - case JsonDbCollator::PrimaryStrength: ucol_setStrength(d->collator, UCOL_PRIMARY); break; - case JsonDbCollator::SecondaryStrength: ucol_setStrength(d->collator, UCOL_SECONDARY); break; - case JsonDbCollator::TertiaryStrength: ucol_setStrength(d->collator, UCOL_TERTIARY); break; - case JsonDbCollator::QuaternaryStrength: ucol_setStrength(d->collator, UCOL_QUATERNARY); break; - case JsonDbCollator::IdenticalStrength: ucol_setStrength(d->collator, UCOL_IDENTICAL); break; - default: - qWarning("Invalid strength mode %d", strength); - } -} - -JsonDbCollator::Strength JsonDbCollator::strength() const -{ - switch (ucol_getStrength(d->collator)) { - case UCOL_PRIMARY: return JsonDbCollator::PrimaryStrength; - case UCOL_SECONDARY: return JsonDbCollator::SecondaryStrength; - case UCOL_QUATERNARY:return JsonDbCollator::QuaternaryStrength; - case UCOL_IDENTICAL: return JsonDbCollator::IdenticalStrength; - case UCOL_TERTIARY: - default: - return JsonDbCollator::TertiaryStrength; - } - return JsonDbCollator::TertiaryStrength; -} - -void JsonDbCollator::setOptions(JsonDbCollator::Options options) -{ - if (d->ref.load() != 1) - detach(); - - d->options = options; - - UErrorCode status = U_ZERO_ERROR; - - if (options & JsonDbCollator::PreferUpperCase) - ucol_setAttribute(d->collator, UCOL_CASE_FIRST, UCOL_UPPER_FIRST, &status); - else if (options & JsonDbCollator::PreferLowerCase) - ucol_setAttribute(d->collator, UCOL_CASE_FIRST, UCOL_LOWER_FIRST, &status); - else - ucol_setAttribute(d->collator, UCOL_CASE_FIRST, UCOL_OFF, &status); - if (U_FAILURE(status)) - qWarning("ucol_setAttribute: Case First failed: %d", status); - - ucol_setAttribute(d->collator, UCOL_FRENCH_COLLATION, - options & JsonDbCollator::FrenchCollation ? UCOL_ON : UCOL_OFF, &status); - if (U_FAILURE(status)) - qWarning("ucol_setAttribute: French collation failed: %d", status); - - ucol_setAttribute(d->collator, UCOL_NORMALIZATION_MODE, - options & JsonDbCollator::DisableNormalization ? UCOL_OFF : UCOL_ON, &status); - if (U_FAILURE(status)) - qWarning("ucol_setAttribute: Normalization mode failed: %d", status); - - ucol_setAttribute(d->collator, UCOL_ALTERNATE_HANDLING, - (options & JsonDbCollator::IgnorePunctuation) ? UCOL_SHIFTED : UCOL_NON_IGNORABLE, &status); - if (U_FAILURE(status)) - qWarning("ucol_setAttribute: Alternate handling failed: %d", status); - - ucol_setAttribute(d->collator, UCOL_CASE_LEVEL, - options & JsonDbCollator::ExtraCaseLevel ? UCOL_ON : UCOL_OFF, &status); - if (U_FAILURE(status)) - qWarning("ucol_setAttribute: Case level failed: %d", status); - - ucol_setAttribute(d->collator, UCOL_HIRAGANA_QUATERNARY_MODE, - options & JsonDbCollator::HiraganaQuaternaryMode ? UCOL_ON : UCOL_OFF, &status); - if (U_FAILURE(status)) - qWarning("ucol_setAttribute: hiragana mode failed: %d", status); - - ucol_setAttribute(d->collator, UCOL_NUMERIC_COLLATION, - options & JsonDbCollator::NumericMode ? UCOL_ON : UCOL_OFF, &status); - if (U_FAILURE(status)) - qWarning("ucol_setAttribute: numeric collation failed: %d", status); -} - -JsonDbCollator::Options JsonDbCollator::options() const -{ - return d->options; -} - -int JsonDbCollator::compare(const QString &s1, const QString &s2) const -{ - return d->compare((ushort *)s1.constData(), s1.size(), (ushort *)s2.constData(), s2.size()); -} - -int JsonDbCollator::compare(const QStringRef &s1, const QStringRef &s2) const -{ - return d->compare((ushort *)s1.constData(), s1.size(), (ushort *)s2.constData(), s2.size()); -} - -int JsonDbCollatorPrivate::compare(ushort *s1, int len1, ushort *s2, int len2) -{ - const UCollationResult result = - ucol_strcoll(collator, (const UChar *)s1, len1, (const UChar *)s2, len2); - return result; -} - -QByteArray JsonDbCollator::sortKey(const QString &string) const -{ - QByteArray result(16 + string.size() + (string.size() >> 2), Qt::Uninitialized); - int size = ucol_getSortKey(d->collator, (const UChar *)string.constData(), - string.size(), (uint8_t *)result.data(), result.size()); - if (size > result.size()) { -#ifdef _DEBUG - qDebug() << "### sortKey realloc from" << result.size() << "to" << size << "for string" << string.size(); -#endif - result.resize(size); - size = ucol_getSortKey(d->collator, (const UChar *)string.constData(), - string.size(), (uint8_t *)result.data(), result.size()); - } - result.truncate(size); - return result; -} -QT_END_NAMESPACE_JSONDB - -#endif // NO_COLLATION_SUPPORT diff --git a/src/common/jsondbcollator.h b/src/common/jsondbcollator.h deleted file mode 100644 index 6214a1a..0000000 --- a/src/common/jsondbcollator.h +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef JSONDBCOLLATOR_H -#define JSONDBCOLLATOR_H - -#ifndef NO_COLLATION_SUPPORT - -#include <QString> -#include <QLocale> - -#include "jsondb-global.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE_JSONDB - -class JsonDbCollatorPrivate; - -class Q_ADDON_JSONDB_EXPORT JsonDbCollator -{ -public: - enum Strength { - PrimaryStrength = 1, - BaseLetterStrength = PrimaryStrength, - - SecondaryStrength = 2, - AccentsStrength = SecondaryStrength, - - TertiaryStrength = 3, - CaseStrength = TertiaryStrength, - - QuaternaryStrength = 4, - PunctuationStrength = QuaternaryStrength, - - IdenticalStrength = 5, - CodepointStrength = IdenticalStrength - }; - - enum Option { - PreferUpperCase = 0x01, - PreferLowerCase = 0x02, - FrenchCollation = 0x04, - DisableNormalization = 0x08, - IgnorePunctuation = 0x10, - ExtraCaseLevel = 0x20, - HiraganaQuaternaryMode = 0x40, - NumericMode = 0x80 - }; - Q_DECLARE_FLAGS(Options, Option) - - enum Collation { - Default, - Big5Han, - Dictionary, - Direct, - GB2312Han, - PhoneBook, - Pinyin, - Phonetic, - Reformed, - Standard, - Stroke, - Traditional, - UniHan - }; - - JsonDbCollator(const QLocale &locale = QLocale(), JsonDbCollator::Collation collation = JsonDbCollator::Default); - JsonDbCollator(const JsonDbCollator &); - ~JsonDbCollator(); - JsonDbCollator &operator=(const JsonDbCollator &); - - void setLocale(const QLocale &locale); - QLocale locale() const; - - void setCollation(Collation collation); - Collation collation() const; - - void setStrength(Strength); - Strength strength() const; - - void setOptions(Options); - Options options() const; - - enum CasePreference { - IgnoreCase = 0x0, - UpperCase = 0x1, - LowerCase = 0x2 - }; - - bool isCaseSensitive() const - { return options() & (PreferUpperCase | PreferLowerCase); } - CasePreference casePreference() const - { - int value = options() & 0x3; - if (value == 3) - return UpperCase; - return CasePreference(value); - } - void setCasePreference(CasePreference c) - { - Options o = options() & ~(PreferUpperCase | PreferLowerCase); - if (c == UpperCase) - o |= PreferUpperCase; - else if (c == LowerCase) - o |= PreferLowerCase; - setOptions(o); - } - - void setNumericMode(bool on) - { setOptions(on ? options() | NumericMode : options() & ~NumericMode); } - bool numericMode() const - { return options() & NumericMode; } - - int compare(const QString &s1, const QString &s2) const; - int compare(const QStringRef &s1, const QStringRef &s2) const; - bool operator()(const QString &s1, const QString &s2) const - { return compare(s1, s2) < 0; } - - QByteArray sortKey(const QString &string) const; - -private: - JsonDbCollatorPrivate *d; - - void detach(); - void init(); -}; - -QT_END_NAMESPACE_JSONDB - -QT_END_HEADER - -#endif // NO_COLLATION_SUPPORT - -#endif // JSONDBCOLLATOR_H diff --git a/src/common/jsondbcollator_p.h b/src/common/jsondbcollator_p.h deleted file mode 100644 index 5a76f29..0000000 --- a/src/common/jsondbcollator_p.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef JSONDBCOLLATOR_P_H -#define JSONDBCOLLATOR_P_H - -#ifndef NO_COLLATION_SUPPORT - -#include "jsondbcollator.h" - -#include <unicode/utypes.h> -#include <unicode/ucol.h> -#include <unicode/ustring.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE_JSONDB - -class JsonDbCollatorPrivate -{ -public: - QAtomicInt ref; - bool modified; - QLocale locale; - JsonDbCollator::Collation collation; - JsonDbCollator::Strength strength; - JsonDbCollator::Options options; - - UCollator *collator; - - JsonDbCollatorPrivate() - : modified(true), - collation(JsonDbCollator::Default), - strength(JsonDbCollator::TertiaryStrength), - options(0), - collator(0) - { ref.store(1); } - ~JsonDbCollatorPrivate(); - - int compare(ushort *s1, int len1, ushort *s2, int len2); -}; - -QT_END_NAMESPACE_JSONDB - -QT_END_HEADER - -#endif // NO_COLLATION_SUPPORT - -#endif // JSONDBCOLLATOR_P_H diff --git a/src/common/jsonstream.cpp b/src/common/jsonstream.cpp deleted file mode 100644 index c2500ef..0000000 --- a/src/common/jsonstream.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "jsonstream.h" -#include <QDebug> -#include <QDataStream> -#include <QLocalSocket> -#include <QAbstractSocket> -#include <QtEndian> - -#ifdef QT_DEBUG -#include <QUdpSocket> -#include <QDateTime> -#include <QCoreApplication> -#endif - -QT_BEGIN_NAMESPACE_JSONDB - -JsonStream::JsonStream(QIODevice *device, QObject *parent) : - QObject(parent), - mDevice(0) -{ - setDevice(device); -} - -QIODevice *JsonStream::device() const -{ - return mDevice; -} - -/** Set the device used by the JsonStream. - The stream does not take ownership of the device. -*/ -void JsonStream::setDevice(QIODevice *device) -{ - if (mDevice) { - disconnect(mDevice, SIGNAL(readyRead()), this, SLOT(deviceReadyRead())); - disconnect(mDevice, SIGNAL(bytesWritten(qint64)), this, SLOT(deviceBytesWritten(qint64))); - disconnect(mDevice, SIGNAL(aboutToClose()), this, SIGNAL(aboutToClose())); - } - mDevice = device; - if (mDevice) { - connect(mDevice, SIGNAL(readyRead()), this, SLOT(deviceReadyRead())); - connect(mDevice, SIGNAL(bytesWritten(qint64)), this, SLOT(deviceBytesWritten(qint64))); - connect(mDevice, SIGNAL(aboutToClose()), this, SIGNAL(aboutToClose())); - } -} - -bool JsonStream::send(const QJsonObject &object) -{ - QByteArray data = QJsonDocument(object).toBinaryData(); - int shouldWrite = data.size(); - if (mWriteBuffer.isEmpty()) { - int didWrite = mDevice->write(data); - if (didWrite < 0) { - qWarning() << "Error writing to socket" << mDevice->errorString(); - } else if (didWrite < shouldWrite) { - mWriteBuffer = data.mid(didWrite); - } - QLocalSocket *s = qobject_cast<QLocalSocket *>(mDevice); - if (s) - s->flush(); - } else { - qWarning() << "Buffering, slow down your writes"; - mWriteBuffer.append(data); - } - return true; -} - -void JsonStream::deviceReadyRead() -{ - while (!mDevice->atEnd()) { - int bytesAvailable = mDevice->bytesAvailable(); - int offset = mReadBuffer.size(); - mReadBuffer.resize(offset + bytesAvailable); - int bytesRead = mDevice->read(mReadBuffer.data()+offset, bytesAvailable); - if (bytesRead < 0) { - qWarning() << "Error reading from socket" << mDevice->errorString(); - continue; - } - while (mReadBuffer.size()) { - QJsonDocument doc(QJsonDocument::fromBinaryData(mReadBuffer, QJsonDocument::Validate)); - if (doc.isEmpty()) - break; - receive(doc.object()); - mReadBuffer = mReadBuffer.mid(doc.toBinaryData().size()); - } - } -} - -void JsonStream::deviceBytesWritten(qint64 bytes) -{ - Q_UNUSED(bytes); - if (!mWriteBuffer.isEmpty()) { - int didWrite = mDevice->write(mWriteBuffer); - mWriteBuffer = mWriteBuffer.mid(didWrite); - } -} - - -#include "moc_jsonstream.cpp" - -QT_END_NAMESPACE_JSONDB diff --git a/src/common/jsonstream.h b/src/common/jsonstream.h deleted file mode 100644 index eab8bda..0000000 --- a/src/common/jsonstream.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef JSON_STREAM_H -#define JSON_STREAM_H - -#include <QIODevice> -#include <qjsondocument.h> -#include <qjsonarray.h> -#include <qjsonobject.h> -#include <qjsonvalue.h> - -#include "jsondb-global.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE_JSONDB - -class JsonStream : public QObject -{ - Q_OBJECT -public: - explicit JsonStream(QIODevice *device = 0, QObject *parent = 0); - - QIODevice *device() const; - void setDevice(QIODevice *device); - - bool send(const QJsonObject &document); - -Q_SIGNALS: - void receive(const QJsonObject &data); - void aboutToClose(); - void readyWrite(); - -protected slots: - void deviceReadyRead(); - void deviceBytesWritten(qint64 bytes); - -private: - - QIODevice *mDevice; - QByteArray mWriteBuffer; - QByteArray mReadBuffer; - -}; - -QT_END_NAMESPACE_JSONDB - -QT_END_HEADER - -#endif // JSON_STREAM_H |