<commit_before>/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdocumentgallery.h"

#include "qabstractgallery_p.h"

#include "qgallerycontainerrequest.h"
#include "qgallerycopyrequest.h"
#include "qgallerycountrequest.h"
#include "qgalleryfilterrequest.h"
#include "qgalleryitemrequest.h"
#include "qgallerymoverequest.h"
#include "qgalleryremoverequest.h"
#include "qgalleryurlrequest.h"

#include "qgalleryerrorresponse_p.h"
#include "qgallerytrackeraggregatelistresponse_p.h"
#include "qgallerytrackercountresponse_p.h"
#include "qgallerytrackerfilecopyresponse_p.h"
#include "qgallerytrackerfilelistresponse_p.h"
#include "qgallerytrackerfilemoveresponse_p.h"
#include "qgallerytrackerfileremoveresponse_p.h"
#include "qgallerytrackerschema_p.h"

#include <QtDBus/qdbusmetatype.h>

QTM_BEGIN_NAMESPACE

class QDocumentGalleryPrivate : public QAbstractGalleryPrivate
{
public:
    QGalleryAbstractResponse *createItemResponse(QGalleryItemRequest *request);
    QGalleryAbstractResponse *createUrlResponse(QGalleryUrlRequest *request);
    QGalleryAbstractResponse *createContainerResponse(QGalleryContainerRequest *request);
    QGalleryAbstractResponse *createFilterResponse(QGalleryFilterRequest *request);
    QGalleryAbstractResponse *createCountResponse(QGalleryCountRequest *request);
    QGalleryAbstractResponse *createCopyResponse(QGalleryCopyRequest *request);
    QGalleryAbstractResponse *createMoveResponse(QGalleryMoveRequest *request);
    QGalleryAbstractResponse *createRemoveResponse(QGalleryRemoveRequest *request);
};

QGalleryAbstractResponse *QDocumentGalleryPrivate::createItemResponse(QGalleryItemRequest *request)
{
    int result = QGalleryAbstractRequest::Succeeded;

    QGalleryTrackerSchema schema;
    schema.resolveItemType(request->itemId());

    QString query = schema.buildIdQuery(&result, request->itemId());

    if (result != QGalleryAbstractRequest::Succeeded) {
        qWarning("Invalid Query %d, %s", result, qPrintable(query));
    } else {
        QGalleryAbstractResponse *response = 0;
        if (schema.isFileType()) {
            response = new QGalleryTrackerFileListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    QStringList(),
                    1);
            response->setCursorPosition(0);
        } else if (schema.isAggregateType()) {
            response = new QGalleryTrackerAggregateListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    QStringList(),
                    1);
            response->setCursorPosition(0);
        } else {
            result = QGalleryAbstractRequest::InvalidItemError;
        }
    }

    return new QGalleryErrorResponse(result);
}


QGalleryAbstractResponse *QDocumentGalleryPrivate::createUrlResponse(
        QGalleryUrlRequest *request)
{
    return 0;
}

QGalleryAbstractResponse *QDocumentGalleryPrivate::createContainerResponse(
        QGalleryContainerRequest *request)
{
    int result = QGalleryAbstractRequest::Succeeded;

    QGalleryTrackerSchema schema;
    schema.setItemType(request->itemType());

    QString query = schema.buildContainerQuery(&result, request->containerId());

    if (result != QGalleryAbstractRequest::Succeeded) {
        qWarning("Invalid Query %d, %s", result, qPrintable(query));
    } else {
        QGalleryAbstractResponse *response = 0;
        if (schema.isFileType()) {
            response = new QGalleryTrackerFileListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    request->sortPropertyNames(),
                    request->minimumPagedItems());
            response->setCursorPosition(request->initialCursorPosition());
        } else if (schema.isAggregateType()) {
            response = new QGalleryTrackerAggregateListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    request->sortPropertyNames(),
                    request->minimumPagedItems());
            response->setCursorPosition(request->initialCursorPosition());
        } else {
            result = QGalleryAbstractRequest::ItemTypeError;
        }
    }

    return new QGalleryErrorResponse(result);
}

QGalleryAbstractResponse *QDocumentGalleryPrivate::createFilterResponse(
        QGalleryFilterRequest *request)
{
    int result = QGalleryAbstractRequest::Succeeded;

    QGalleryTrackerSchema schema;
    schema.setItemType(request->itemType());

    QString query = schema.buildFilterQuery(&result, request->containerId(), request->filter());

    qDebug("filter response %s: %s", qPrintable(schema.service()), qPrintable(query));

    if (result != QGalleryAbstractRequest::Succeeded) {
        qWarning("Invalid Query %d, %s", result, qPrintable(query));
    } else {
        if (schema.isFileType()) {
            QGalleryAbstractResponse *response = new QGalleryTrackerFileListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    request->sortPropertyNames(),
                    request->minimumPagedItems());
            response->setCursorPosition(request->initialCursorPosition());

            return response;
        } else if (schema.isAggregateType()) {
            QGalleryAbstractResponse *response = new QGalleryTrackerAggregateListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    request->sortPropertyNames(),
                    request->minimumPagedItems());
            response->setCursorPosition(request->initialCursorPosition());

            return response;
        } else {
            result = QGalleryAbstractRequest::ItemTypeError;<commit_msg>Remove debug message.<commit_after>/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdocumentgallery.h"

#include "qabstractgallery_p.h"

#include "qgallerycontainerrequest.h"
#include "qgallerycopyrequest.h"
#include "qgallerycountrequest.h"
#include "qgalleryfilterrequest.h"
#include "qgalleryitemrequest.h"
#include "qgallerymoverequest.h"
#include "qgalleryremoverequest.h"
#include "qgalleryurlrequest.h"

#include "qgalleryerrorresponse_p.h"
#include "qgallerytrackeraggregatelistresponse_p.h"
#include "qgallerytrackercountresponse_p.h"
#include "qgallerytrackerfilecopyresponse_p.h"
#include "qgallerytrackerfilelistresponse_p.h"
#include "qgallerytrackerfilemoveresponse_p.h"
#include "qgallerytrackerfileremoveresponse_p.h"
#include "qgallerytrackerschema_p.h"

#include <QtDBus/qdbusmetatype.h>

QTM_BEGIN_NAMESPACE

class QDocumentGalleryPrivate : public QAbstractGalleryPrivate
{
public:
    QGalleryAbstractResponse *createItemResponse(QGalleryItemRequest *request);
    QGalleryAbstractResponse *createUrlResponse(QGalleryUrlRequest *request);
    QGalleryAbstractResponse *createContainerResponse(QGalleryContainerRequest *request);
    QGalleryAbstractResponse *createFilterResponse(QGalleryFilterRequest *request);
    QGalleryAbstractResponse *createCountResponse(QGalleryCountRequest *request);
    QGalleryAbstractResponse *createCopyResponse(QGalleryCopyRequest *request);
    QGalleryAbstractResponse *createMoveResponse(QGalleryMoveRequest *request);
    QGalleryAbstractResponse *createRemoveResponse(QGalleryRemoveRequest *request);
};

QGalleryAbstractResponse *QDocumentGalleryPrivate::createItemResponse(QGalleryItemRequest *request)
{
    int result = QGalleryAbstractRequest::Succeeded;

    QGalleryTrackerSchema schema;
    schema.resolveItemType(request->itemId());

    QString query = schema.buildIdQuery(&result, request->itemId());

    if (result != QGalleryAbstractRequest::Succeeded) {
        qWarning("Invalid Query %d, %s", result, qPrintable(query));
    } else {
        QGalleryAbstractResponse *response = 0;
        if (schema.isFileType()) {
            response = new QGalleryTrackerFileListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    QStringList(),
                    1);
            response->setCursorPosition(0);
        } else if (schema.isAggregateType()) {
            response = new QGalleryTrackerAggregateListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    QStringList(),
                    1);
            response->setCursorPosition(0);
        } else {
            result = QGalleryAbstractRequest::InvalidItemError;
        }
    }

    return new QGalleryErrorResponse(result);
}


QGalleryAbstractResponse *QDocumentGalleryPrivate::createUrlResponse(
        QGalleryUrlRequest *request)
{
    return 0;
}

QGalleryAbstractResponse *QDocumentGalleryPrivate::createContainerResponse(
        QGalleryContainerRequest *request)
{
    int result = QGalleryAbstractRequest::Succeeded;

    QGalleryTrackerSchema schema;
    schema.setItemType(request->itemType());

    QString query = schema.buildContainerQuery(&result, request->containerId());

    if (result != QGalleryAbstractRequest::Succeeded) {
        qWarning("Invalid Query %d, %s", result, qPrintable(query));
    } else {
        QGalleryAbstractResponse *response = 0;
        if (schema.isFileType()) {
            response = new QGalleryTrackerFileListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    request->sortPropertyNames(),
                    request->minimumPagedItems());
            response->setCursorPosition(request->initialCursorPosition());
        } else if (schema.isAggregateType()) {
            response = new QGalleryTrackerAggregateListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    request->sortPropertyNames(),
                    request->minimumPagedItems());
            response->setCursorPosition(request->initialCursorPosition());
        } else {
            result = QGalleryAbstractRequest::ItemTypeError;
        }
    }

    return new QGalleryErrorResponse(result);
}

QGalleryAbstractResponse *QDocumentGalleryPrivate::createFilterResponse(
        QGalleryFilterRequest *request)
{
    int result = QGalleryAbstractRequest::Succeeded;

    QGalleryTrackerSchema schema;
    schema.setItemType(request->itemType());

    QString query = schema.buildFilterQuery(&result, request->containerId(), request->filter());

    if (result != QGalleryAbstractRequest::Succeeded) {
        qWarning("Invalid Query %d, %s", result, qPrintable(query));
    } else {
        if (schema.isFileType()) {
            QGalleryAbstractResponse *response = new QGalleryTrackerFileListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    request->sortPropertyNames(),
                    request->minimumPagedItems());
            response->setCursorPosition(request->initialCursorPosition());

            return response;
        } else if (schema.isAggregateType()) {
            QGalleryAbstractResponse *response = new QGalleryTrackerAggregateListResponse(
                    QDBusConnection::sessionBus(),
                    schema,
                    query,
                    request->propertyNames(),
                    request->sortPropertyNames(),
                    request->minimumPagedItems());
            response->setCursorPosition(request->initialCursorPosition());

            return response;
        } else {
            result = QGalleryAbstractRequest::ItemTypeError;
{'fraction_non_alphanumeric': 0.11197573199683461, 'fraction_numerical': 0.002505935109469797, 'mean_word_length': 3.1075297941495124, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4661290', 'n_tokens_mistral': 3937, 'n_tokens_neox': 3704, 'n_words': 849}