|
1 /* |
|
2 * Copyright (c) 2006 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 the License "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: Recognizer for the widget supported MIME types. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "WidgetRecognizer.h" |
|
19 #include "ImplementationProxy.h" |
|
20 |
|
21 // CONSTANTS |
|
22 _LIT(KWidgetExtension, ".wgz"); |
|
23 _LIT8(KWidgetMimeType,"application/x-nokia-widget"); |
|
24 |
|
25 // |
|
26 // CWidgetsRecognizer |
|
27 // |
|
28 |
|
29 // ====================== MEMBER FUNCTIONS ============================= |
|
30 |
|
31 // ============================================================================ |
|
32 // CWidgetRecognizer::CWidgetRecognizer() |
|
33 // Default constructor |
|
34 // |
|
35 // @since 3.1 |
|
36 // ============================================================================ |
|
37 CWidgetRecognizer::CWidgetRecognizer() |
|
38 :CApaDataRecognizerType( KUidMimeWidgetRecognizer, CApaDataRecognizerType::EHigh ) |
|
39 { |
|
40 iCountDataTypes = 1; |
|
41 } |
|
42 |
|
43 // ============================================================================ |
|
44 // From CApaDataRecognizerType |
|
45 // Gets the size of buffer preferred for the purpose of recognizing the data type. |
|
46 // @return The preferred data size. |
|
47 // @since 3.1 |
|
48 // ============================================================================ |
|
49 TUint CWidgetRecognizer::PreferredBufSize() |
|
50 { |
|
51 return 0x80; |
|
52 } |
|
53 |
|
54 // ============================================================================ |
|
55 // From CApaDataRecognizerType |
|
56 // Gets one of the data (MIME) types that the recognizer can recognize. |
|
57 // @param aIndex - An index that identifies the data type. Typically, |
|
58 // the minimum value is zero and the maximum value is the value of MimeTypesCount() - 1. |
|
59 // |
|
60 // @return The data (MIME) type. |
|
61 // @since 3.1 |
|
62 // ============================================================================ |
|
63 TDataType CWidgetRecognizer::SupportedDataTypeL( TInt /*aIndex*/ ) const |
|
64 { |
|
65 // only support one widget mime type |
|
66 return TDataType( KWidgetMimeType() ); |
|
67 } |
|
68 |
|
69 // ============================================================================ |
|
70 // From CApaDataRecognizerType |
|
71 // This implements recognition behaviour -- called by RecognizeL() |
|
72 // @param aName - The name of the data; typically this is a file name |
|
73 // containing the data to be recognized. |
|
74 // @param aBuffer - A buffer containing data to be recognized; typically, |
|
75 // this is read from the start of the file containing the data. |
|
76 // |
|
77 // @return void. |
|
78 // @since 3.1 |
|
79 // ============================================================================ |
|
80 void CWidgetRecognizer::DoRecognizeL( const TDesC& aName, const TDesC8& /*aBuffer*/ ) |
|
81 { |
|
82 iConfidence = ENotRecognized; |
|
83 |
|
84 if ( aName.Length() >= 4 ) |
|
85 { |
|
86 TInt dotPos = aName.LocateReverse( '.' ); |
|
87 if ( dotPos != KErrNotFound ) |
|
88 { |
|
89 TInt extLength = aName.Length() - dotPos; |
|
90 HBufC* ext = aName.Right( extLength ).AllocL(); |
|
91 CleanupStack::PushL( ext ); |
|
92 |
|
93 // recognize .wgz extensions. |
|
94 if (ext->CompareF( KWidgetExtension ) == 0) |
|
95 { |
|
96 iDataType = TDataType( KWidgetMimeType ); |
|
97 iConfidence = ECertain; |
|
98 } |
|
99 CleanupStack::PopAndDestroy(); // ext |
|
100 } |
|
101 } |
|
102 } |
|
103 |
|
104 // ============================================================================ |
|
105 // CWidgetRecognizer::CreateRecognizerL |
|
106 // Create CWidgetRecognizer instance |
|
107 // ============================================================================ |
|
108 // |
|
109 CApaDataRecognizerType* CWidgetRecognizer::CreateRecognizerL() |
|
110 { |
|
111 return new (ELeave) CWidgetRecognizer(); |
|
112 } |
|
113 |
|
114 // Implementation table contains only one entry for widget recognizer |
|
115 const TImplementationProxy ImplementationTable[] = |
|
116 { |
|
117 IMPLEMENTATION_PROXY_ENTRY(KWidgetRecognizerImplUIDValue, CWidgetRecognizer::CreateRecognizerL) |
|
118 }; |
|
119 |
|
120 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
121 |
|
122 // ============================================================================ |
|
123 // ImplementationGroupProxy |
|
124 // Returns the filters implemented in this DLL |
|
125 // Returns: The filters implemented in this DLL |
|
126 // ============================================================================ |
|
127 // |
|
128 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
129 { |
|
130 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
131 return ImplementationTable; |
|
132 } |