searchui/indevicehandler/src/indevicehandler.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 03 May 2010 12:32:15 +0300
changeset 2 208a4ba3894c
parent 0 ccd0fd43f247
child 15 df6898e696c6
child 17 7d8c8d8f5eab
permissions -rw-r--r--
Revision: 201015 Kit: 201018

/*
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *
 * Description:  Implementation indevice handler
 *
 */
#include "indevicehandler.h"
#include <qcpixsearcher.h>
#include <qcpixdocument.h>

// ---------------------------------------------------------------------------
// InDeviceHandler::InDeviceHandler()
// ---------------------------------------------------------------------------
//
InDeviceHandler::InDeviceHandler() :
    mSearchInterface(0), mSearchResultCount(0)
    {
    }
// ---------------------------------------------------------------------------
// InDeviceHandler::~InDeviceHandler()
// ---------------------------------------------------------------------------
//
InDeviceHandler::~InDeviceHandler()
    {
    if (mSearchInterface)
        {
        delete mSearchInterface;

        }
    }

// ---------------------------------------------------------------------------
// InDeviceHandler::getSearchResult(int aError, int estimatedResultCount)
// aError: error code
// estimatedResultCount: number of hits
// ---------------------------------------------------------------------------
//
void InDeviceHandler::getSearchResult(int aError, int estimatedResultCount)
    {
    qDebug() << aError << estimatedResultCount;
    mSearchResultCount = estimatedResultCount;
    emit handleAsyncSearchResult(aError, estimatedResultCount);
    }
// ---------------------------------------------------------------------------
// InDeviceHandler::getDocumentAsync(int aError, QCPixDocument* aDocument)
// aError: error code
// aDocument: holding the result item
// ---------------------------------------------------------------------------
//
void InDeviceHandler::getDocumentAsync(int aError, QCPixDocument* aDocument)
    {
    emit handleDocument(aError, aDocument);
    }
// ---------------------------------------------------------------------------
// InDeviceHandler::getDocumentAtIndex(int aIndex)
// aIndex: item index to be found
// ---------------------------------------------------------------------------
//
QCPixDocument* InDeviceHandler::getDocumentAtIndex(int aIndex)
    {
    QCPixDocument* doc = NULL;
    if (mSearchInterface)
        {
        try
            {
            doc = mSearchInterface->getDocument(aIndex);

            }
        catch (...)
            {
            delete doc;
            return NULL;
            }
        }
    return doc;
    }


// ---------------------------------------------------------------------------
// InDeviceHandler::getSearchResultCount()
// gets the number of hits
// ---------------------------------------------------------------------------
//
int InDeviceHandler::getSearchResultCount()
    {
    return mSearchResultCount;
    }
// ---------------------------------------------------------------------------
// InDeviceHandler::getDocumentAsyncAtIndex(int aIndex)
// aIndex :  index of item to be found async
// ---------------------------------------------------------------------------
//
void InDeviceHandler::getDocumentAsyncAtIndex(int aIndex)
    {
    if (mSearchInterface)
        {
        try
            {
            mSearchInterface->getDocumentAsync(aIndex);
            }
        catch (...)
            {
            // handle the exception
            return;
            }
        }

    }
// ---------------------------------------------------------------------------
// InDeviceHandler::searchAsync
// aSearchAsyncString: string to be searched
// async
// ---------------------------------------------------------------------------
//
void InDeviceHandler::searchAsync(QString aSearchAsyncString, QString/* aDefaultSearchField*/)
    {
    if (aSearchAsyncString.length())
        {
        mSearchResultCount = 0;
        if (mSearchInterface)
            {
            try
                {
                mSearchInterface->searchAsync(aSearchAsyncString);
                }
            catch (...)
                {
                // handle the exception
                return;
                }
            }
        }
    }
// ---------------------------------------------------------------------------
// InDeviceHandler::cancelLastSearch()
// ---------------------------------------------------------------------------
//
void InDeviceHandler::cancelLastSearch()
    {
    if (mSearchInterface)

        {
        try
            {
            mSearchInterface->cancelSearch();
            }
        catch (...)
            {
            // handle the exception
            return;
            }
        }
    }
// ---------------------------------------------------------------------------
// InDeviceHandler::setCategory
// astring: setting categories to be searched
// ---------------------------------------------------------------------------
//
void InDeviceHandler::setCategory(QString astring)
    {
    if (mSearchInterface)
        {
        delete mSearchInterface;
        mSearchInterface = NULL;
        }
    if (astring.length())
        {
        QString database("root ");
        database.append(astring);
        mSearchInterface = QCPixSearcher::newInstance(database,
                DEFAULT_SEARCH_FIELD);
        }
    else
        {
        mSearchInterface = QCPixSearcher::newInstance("root",
        DEFAULT_SEARCH_FIELD);
        }
    if (mSearchInterface)
        {
        try
            {
            mSearchInterface->connect(mSearchInterface,
                    SIGNAL(handleSearchResults(int,int)), this,
                    SLOT(getSearchResult(int,int)));
            }
        catch (...)
            {
            // handle the exception
            }

        try
            {
            mSearchInterface->connect(mSearchInterface,
                    SIGNAL(handleDocument(int,QCPixDocument*)), this,
                    SLOT(getDocumentAsync(int,QCPixDocument*)));
            }
        catch (...)
            {
            // handle the exception
            }
        }
    }

// ---------------------------------------------------------------------------
// InDeviceHandler::isPrepared()
// verify the mSearchInterface is prepared or not
// ---------------------------------------------------------------------------
//
bool InDeviceHandler::isPrepared()
    {
    if (mSearchInterface)
        {
        return true;
        }

    return false;

    }