searchui/indevicehandler/src/indevicehandler.cpp
changeset 0 ccd0fd43f247
child 2 208a4ba3894c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/searchui/indevicehandler/src/indevicehandler.cpp	Mon Apr 19 14:40:05 2010 +0300
@@ -0,0 +1,243 @@
+/*
+ * 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::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:: search(QString aSearchString)
+// aSearchString: string to be searched sync
+// ---------------------------------------------------------------------------
+//
+void InDeviceHandler::search(QString aSearchString)
+    {
+    qDebug() << "InDeviceHandler::search Enter";
+    if (aSearchString.length())
+        {
+        int error = 0;
+        mSearchResultCount = 0;
+        if (mSearchInterface)
+            {
+            try
+                {
+                mSearchResultCount = mSearchInterface->search(aSearchString);
+                }
+            catch (...)
+                {
+                error = -1;
+                }
+            }
+        emit handleSearchResult(error, mSearchResultCount);
+        }
+    qDebug() << "InDeviceHandler::search Exit";
+    }
+// ---------------------------------------------------------------------------
+// InDeviceHandler::~InDeviceHandler()
+// ---------------------------------------------------------------------------
+//
+InDeviceHandler::~InDeviceHandler()
+    {
+    if (mSearchInterface)
+        {
+        delete mSearchInterface;
+
+        }
+    }
+// ---------------------------------------------------------------------------
+// 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(QString aSearchAsyncString, QString/* aDefaultSearchField*/)
+// 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(QString astring)
+// 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);
+        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;
+
+    }