|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <cpixsearcher.h> |
|
19 #include <cpixcommon.h> |
|
20 #include <CCPixSearcher.h> |
|
21 #include <CSearchDocument.h> |
|
22 |
|
23 #include "cpixsearcherprivate.h" |
|
24 #include "cpixutils.h" |
|
25 |
|
26 /** |
|
27 * Note: Code in this file should never throw OR leak symbian exceptions. |
|
28 * Convert all leaves to C++ exceptions. |
|
29 */ |
|
30 |
|
31 CpixSearcher::CpixSearcher() |
|
32 :iPvtImpl( new CpixSearcherPrivate( this ) ) |
|
33 { |
|
34 PERF_SEARCH_START_TIMER |
|
35 PERF_GETDOC_START_TIMER |
|
36 } |
|
37 |
|
38 CpixSearcher::~CpixSearcher() |
|
39 { |
|
40 delete iPvtImpl; |
|
41 } |
|
42 |
|
43 CpixSearcher* CpixSearcher::newInstance() |
|
44 { |
|
45 CpixSearcher* searcher = NULL; |
|
46 try{ |
|
47 searcher = new CpixSearcher(); |
|
48 searcher->iPvtImpl->Construct( QString() ); |
|
49 } |
|
50 catch(...){ |
|
51 delete searcher; |
|
52 return NULL; |
|
53 } |
|
54 return searcher; |
|
55 } |
|
56 |
|
57 CpixSearcher* CpixSearcher::newInstance( QString aBaseAppClass, QString aDefaultSearchField ) |
|
58 { |
|
59 CpixSearcher* searcher = NULL; |
|
60 try{ |
|
61 searcher = new CpixSearcher(); |
|
62 searcher->iPvtImpl->Construct( aDefaultSearchField ); |
|
63 searcher->setDatabase( aBaseAppClass ); |
|
64 } |
|
65 catch(...){ |
|
66 delete searcher->iPvtImpl; |
|
67 return NULL; |
|
68 } |
|
69 return searcher; |
|
70 } |
|
71 |
|
72 void CpixSearcher::setDatabase( QString aBaseAppClass ) |
|
73 { |
|
74 QT_TRAP_THROWING( |
|
75 TBuf<KMaxStringLength> baseAppClass( aBaseAppClass.utf16() ); |
|
76 iPvtImpl->iSearcher->OpenDatabaseL( baseAppClass ) ; |
|
77 ); //end of QT_TRAP_THROWING |
|
78 } |
|
79 |
|
80 void CpixSearcher::setDatabaseAsync( QString aBaseAppClass ) |
|
81 { |
|
82 QT_TRAP_THROWING( |
|
83 TBuf<KMaxStringLength> baseAppClass( aBaseAppClass.utf16() ); |
|
84 iPvtImpl->iSearcher->OpenDatabaseL( *iPvtImpl, baseAppClass ) |
|
85 ); //end of QT_TRAP_THROWING |
|
86 } |
|
87 |
|
88 //The following bit of code is common to two functions - this helps to avoid duplication. |
|
89 //However, macros make debugging difficult - so, if you need to debug, copy the code below |
|
90 //and replace the macro, fix the code and bring the fix back to the macro. |
|
91 #define CREATE_SEARCH_VARS \ |
|
92 HBufC* searchString = HBufC::NewL( aSearchString.length() + 1 ); \ |
|
93 TPtrC searchStringPtr( reinterpret_cast<const TUint16*>( aSearchString.utf16() ) ); \ |
|
94 searchString->Des().Copy( searchStringPtr ); \ |
|
95 \ |
|
96 HBufC* defaultSearchField = HBufC::NewL( aDefaultSearchField.length() + 1 ); \ |
|
97 TPtrC aDefaultSearchFieldPtr( reinterpret_cast<const TUint16*>( aDefaultSearchField.utf16() ) );\ |
|
98 defaultSearchField->Des().Copy( aDefaultSearchFieldPtr ); |
|
99 |
|
100 #define DELETE_SEARCH_VARS \ |
|
101 delete searchString;\ |
|
102 delete defaultSearchField; |
|
103 |
|
104 int CpixSearcher::search( QString aSearchString, QString aDefaultSearchField ) |
|
105 { |
|
106 PERF_SEARCH_RESTART_TIMER |
|
107 int tmp = 0; |
|
108 QT_TRAP_THROWING( |
|
109 CREATE_SEARCH_VARS; |
|
110 //ideally would have had just the following single line: |
|
111 //QT_TRAP_THROWING( return iPvtImpl->iSearcher->SearchL( searchString, defaultSearchField ) ); |
|
112 //But the RCVT compiler throws up warnings. The following is just to suppress those warnings. |
|
113 tmp = iPvtImpl->iSearcher->SearchL( *searchString, *defaultSearchField ); |
|
114 DELETE_SEARCH_VARS; |
|
115 ); //QT_TRAP_THROWING |
|
116 |
|
117 PERF_SEARCH_ENDLOG |
|
118 return tmp; |
|
119 } |
|
120 |
|
121 void CpixSearcher::searchAsync( QString aSearchString, QString aDefaultSearchField ) |
|
122 { |
|
123 PERF_TIME_NOW("Async search start") |
|
124 QT_TRAP_THROWING( |
|
125 CREATE_SEARCH_VARS; |
|
126 iPvtImpl->iSearcher->SearchL( *iPvtImpl, *searchString, *defaultSearchField ); |
|
127 DELETE_SEARCH_VARS; |
|
128 ); //QT_TRAP_THROWING |
|
129 } |
|
130 |
|
131 CpixDocument* CpixSearcher::document( int aIndex ) |
|
132 { |
|
133 PERF_GETDOC_RESTART_TIMER |
|
134 CpixDocument* tmp = 0; |
|
135 QT_TRAP_THROWING( tmp = CpixDocFromCSearchDocument( iPvtImpl->iSearcher->GetDocumentL( aIndex ) ) ); |
|
136 PERF_GETDOC_ENDLOG |
|
137 return tmp; |
|
138 } |
|
139 |
|
140 void CpixSearcher::documentAsync( int aIndex ) |
|
141 { |
|
142 PERF_TIME_NOW("Async get document start") |
|
143 QT_TRAP_THROWING( iPvtImpl->iSearcher->GetDocumentL( aIndex, *iPvtImpl ) ); |
|
144 } |
|
145 |
|
146 void CpixSearcher::cancelSearch() |
|
147 { |
|
148 iPvtImpl->iSearcher->Cancel(); |
|
149 } |