📄 class_c_br_ctl_sample_app_link_resolver.html
字号:
<td class="mdname" nowrap> <em>aFileName</em>, </td> </tr> <tr> <td class="md" nowrap align="right"></td> <td class="md"></td> <td class="md" nowrap>const TDesC8 & </td> <td class="mdname" nowrap> <em>aData</em></td> </tr> <tr> <td class="md"></td> <td class="md">) </td> <td class="md" colspan="2"><code> [private]</code></td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>Rcognize the mime type. <p>Definition at line <a class="el" href="_br_ctl_sample_app_link_resolver_8cpp-source.html#l00162">162</a> of file <a class="el" href="_br_ctl_sample_app_link_resolver_8cpp-source.html">BrCtlSampleAppLinkResolver.cpp</a>.<div class="fragment"><pre class="fragment"><a name="l00163"></a>00163 {<a name="l00164"></a>00164 TDataRecognitionResult dataType;<a name="l00165"></a>00165 RApaLsSession apaSession;<a name="l00166"></a>00166 TInt ret;<a name="l00167"></a>00167 HBufC* contentTypeString = NULL;<a name="l00168"></a>00168 <a name="l00169"></a>00169 User::LeaveIfError(apaSession.Connect());<a name="l00170"></a>00170 <span class="comment">// Ask the application architecture to find the file type</span><a name="l00171"></a>00171 ret = apaSession.RecognizeData(aFileName, aData, dataType);<a name="l00172"></a>00172 apaSession.Close();<a name="l00173"></a>00173 <a name="l00174"></a>00174 <span class="keywordflow">if</span> (ret == KErrNone &&<a name="l00175"></a>00175 (dataType.iConfidence == CApaDataRecognizerType::ECertain) ||<a name="l00176"></a>00176 (dataType.iConfidence == CApaDataRecognizerType::EProbable))<a name="l00177"></a>00177 {<a name="l00178"></a>00178 <span class="comment">// If the file type was found, try to match it to a known file type</span><a name="l00179"></a>00179 TPtrC8 mimeTypePtr = dataType.iDataType.Des8();<a name="l00180"></a>00180 TInt len = mimeTypePtr.Length() + 1;<a name="l00181"></a>00181 contentTypeString = HBufC::NewL(len); <a name="l00182"></a>00182 contentTypeString->Des().Copy(mimeTypePtr);<a name="l00183"></a>00183 contentTypeString->Des().ZeroTerminate();<a name="l00184"></a>00184 }<a name="l00185"></a>00185 CleanupStack::PushL(contentTypeString);<a name="l00186"></a>00186 <span class="keywordflow">return</span> contentTypeString;<a name="l00187"></a>00187 }</pre></div><p> </td> </tr></table><a class="anchor" name="fd74fceb06b713999b023e18fb096b64"></a><!-- doxytag: member="CBrCtlSampleAppLinkResolver::GetFileNameL" ref="fd74fceb06b713999b023e18fb096b64" args="(const TDesC &aFileName)" --><p><table class="mdTable" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top">TBool CBrCtlSampleAppLinkResolver::GetFileNameL </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">const TDesC & </td> <td class="mdname1" valign="top" nowrap> <em>aFileName</em> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap><code> [private]</code></td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>Translate the file name from a URL to a valid file name in the system.. <p>Definition at line <a class="el" href="_br_ctl_sample_app_link_resolver_8cpp-source.html#l00195">195</a> of file <a class="el" href="_br_ctl_sample_app_link_resolver_8cpp-source.html">BrCtlSampleAppLinkResolver.cpp</a>.<div class="fragment"><pre class="fragment"><a name="l00196"></a>00196 {<a name="l00197"></a>00197 <span class="comment">// This function accepts URLs in the following format:</span><a name="l00198"></a>00198 <span class="comment">// file://filename.xxx</span><a name="l00199"></a>00199 <span class="comment">// file:///filename.xxx</span><a name="l00200"></a>00200 <span class="comment">// file://c:/filename.xxx</span><a name="l00201"></a>00201 <span class="comment">// file:///c:/filename.xxx</span><a name="l00202"></a>00202 <span class="comment">//</span><a name="l00203"></a>00203 _LIT(KFileScheme, <span class="stringliteral">"file://"</span>);<a name="l00204"></a>00204 _LIT(KDefaultDrivePath, <span class="stringliteral">"C:\\"</span>);<a name="l00205"></a>00205 _LIT(KPathChar, <span class="stringliteral">"\\"</span>);<a name="l00206"></a>00206 <a name="l00207"></a>00207 TInt count;<a name="l00208"></a>00208 TInt index = 0;<a name="l00209"></a>00209 TBool drvLetter = EFalse;<a name="l00210"></a>00210 TUint16 c;<a name="l00211"></a>00211 <a name="l00212"></a>00212 <span class="comment">// Verify the file scheme</span><a name="l00213"></a>00213 TPtrC urlPtr(aFileName);<a name="l00214"></a>00214 <span class="keywordflow">if</span> (urlPtr.FindF(KFileScheme) != 0)<a name="l00215"></a>00215 {<a name="l00216"></a>00216 <span class="keywordflow">return</span> EFalse;<a name="l00217"></a>00217 }<a name="l00218"></a>00218 urlPtr.Set(urlPtr.Mid(KFileScheme().Length()));<a name="l00219"></a>00219 <a name="l00220"></a>00220 <span class="comment">// make sure there are enough characters in the filename before</span><a name="l00221"></a>00221 <span class="comment">// trying to check them</span><a name="l00222"></a>00222 count = urlPtr.Length();<a name="l00223"></a>00223 <span class="keywordflow">if</span>(count == 0)<a name="l00224"></a>00224 {<a name="l00225"></a>00225 <span class="keywordflow">return</span> EFalse; <span class="comment">// no filename, so can't look at urlPtr[0]</span><a name="l00226"></a>00226 }<a name="l00227"></a>00227 <a name="l00228"></a>00228 <span class="comment">// Skip the first '/' if there is one</span><a name="l00229"></a>00229 <span class="keywordflow">if</span> (urlPtr[0] == <span class="charliteral">'/'</span>)<a name="l00230"></a>00230 {<a name="l00231"></a>00231 urlPtr.Set(urlPtr.Mid(1));<a name="l00232"></a>00232 }<a name="l00233"></a>00233 count = urlPtr.Length();<a name="l00234"></a>00234 <a name="l00235"></a>00235 <span class="comment">// Is there a drive letter?</span><a name="l00236"></a>00236 <span class="keywordflow">if</span>(count > 1)<a name="l00237"></a>00237 {<a name="l00238"></a>00238 <span class="comment">// can check for drive letter</span><a name="l00239"></a>00239 <span class="keywordflow">if</span> (urlPtr[1 + index] == <span class="charliteral">':'</span>)<a name="l00240"></a>00240 {<a name="l00241"></a>00241 drvLetter = ETrue;<a name="l00242"></a>00242 }<a name="l00243"></a>00243 }<a name="l00244"></a>00244 <span class="keywordflow">if</span>(drvLetter == EFalse)<a name="l00245"></a>00245 {<a name="l00246"></a>00246 <span class="comment">// 3 additional characters for the string "c:\"</span><a name="l00247"></a>00247 count = urlPtr.Length() + 3;<a name="l00248"></a>00248 }<a name="l00249"></a>00249 <a class="code" href="class_c_br_ctl_sample_app_link_resolver.html#17710d20100c676856cfb8e54134a8c3">iFileName</a> = HBufC::NewL(count);<a name="l00250"></a>00250 <span class="keywordflow">if</span> (!drvLetter)<a name="l00251"></a>00251 {<a name="l00252"></a>00252 <a class="code" href="class_c_br_ctl_sample_app_link_resolver.html#17710d20100c676856cfb8e54134a8c3">iFileName</a>->Des().Append(KDefaultDrivePath);<a name="l00253"></a>00253 }<a name="l00254"></a>00254 <a name="l00255"></a>00255 TBool fragment(EFalse);<a name="l00256"></a>00256 <span class="comment">// Convert relative path containing /./ and /../ to absolute path</span><a name="l00257"></a>00257 <span class="keywordflow">for</span> (; index < urlPtr.Length() && !fragment; index ++)<a name="l00258"></a>00258 {<a name="l00259"></a>00259 <span class="keywordflow">switch</span>(urlPtr[index])<a name="l00260"></a>00260 {<a name="l00261"></a>00261 <span class="keywordflow">case</span> <span class="charliteral">'#'</span>: <span class="comment">//Check if there is a fragment '#'</span><a name="l00262"></a>00262 {<a name="l00263"></a>00263 fragment = ETrue;<a name="l00264"></a>00264 <span class="keywordflow">continue</span>; <span class="comment">// Just stop there</span><a name="l00265"></a>00265 }<a name="l00266"></a>00266 <a name="l00267"></a>00267 <span class="keywordflow">case</span> <span class="charliteral">'/'</span>:<a name="l00268"></a>00268 {<a name="l00269"></a>00269 <a class="code" href="class_c_br_ctl_sample_app_link_resolver.html#17710d20100c676856cfb8e54134a8c3">iFileName</a>->Des().Append(KPathChar);<a name="l00270"></a>00270 <span class="keywordflow">break</span>;<a name="l00271"></a>00271 }<a name="l00272"></a>00272 <span class="keywordflow">case</span> <span class="charliteral">'.'</span>:<a name="l00273"></a>00273 {<a name="l00274"></a>00274 <span class="keywordflow">if</span> (index > 1 && urlPtr[index - 1] == <span class="charliteral">'/'</span>)<a name="l00275"></a>00275 {<a name="l00276"></a>00276 <span class="keywordflow">if</span> (index < count - 1 && urlPtr[index + 1] == <span class="charliteral">'/'</span>)<a name="l00277"></a>00277 {<a name="l00278"></a>00278 index ++; <span class="comment">// skip ./</span><a name="l00279"></a>00279 <span class="keywordflow">break</span>;<a name="l00280"></a>00280 }<a name="l00281"></a>00281 <span class="keywordflow">if</span> (index > 2 && index < count - 3 &&<a name="l00282"></a>00282 urlPtr[index + 1] == <span class="charliteral">'.'</span> && urlPtr[index + 2] == <span class="charliteral">'/'</span>)<a name="l00283"></a>00283 {<a name="l00284"></a>00284 TInt i = index - 2;<a name="l00285"></a>00285 <a name="l00286"></a>00286 <span class="keywordflow">for</span> (; i > 0 && urlPtr[i] != <span class="charliteral">'/'</span>; i--) {} <span class="comment">// skip /../</span><a name="l00287"></a>00287 <a name="l00288"></a>00288 <a class="code" href="class_c_br_ctl_sample_app_link_resolver.html#17710d20100c676856cfb8e54134a8c3">iFileName</a>->Des().SetLength(<a class="code" href="class_c_br_ctl_sample_app_link_resolver.html#17710d20100c676856cfb8e54134a8c3">iFileName</a>->Des().Length() - (index - i));<a name="l00289"></a>00289 index += 2;<a name="l00290"></a>00290 <span class="keywordflow">break</span>;<a name="l00291"></a>00291 }<a name="l00292"></a>00292 }<a name="l00293"></a>00293 }<a name="l00294"></a>00294 <span class="comment">// no break</span><a name="l00295"></a>00295 <span class="comment">//lint -fallthrough</span><a name="l00296"></a>00296 <a name="l00297"></a>00297 <span class="keywordflow">default</span>:<a name="l00298"></a>00298 {<a name="l00299"></a>00299 c = urlPtr[index];<a name="l00300"></a>00300 <a class="code" href="class_c_br_ctl_sample_app_link_resolver.html#17710d20100c676856cfb8e54134a8c3">iFileName</a>->Des().Append(&c, 1);<a name="l00301"></a>00301 <span class="keywordflow">break</span>;<a name="l00302"></a>00302 }<a name="l00303"></a>00303 } <span class="comment">// end of switch</span><a name="l00304"></a>00304 }<a name="l00305"></a>00305 <span class="keywordflow">return</span> ETrue;<a name="l00306"></a>00306 }</pre></div><p> </td> </tr></table><hr><table x-use-null-cells style="x-cell-content-align: top; width: 100%; border-spacing: 0px; border-spacing: 0px;" cellspacing=0 width=100%> <col style="width: 50%;"> <col style="width: 50%;"> <tr style="x-cell-content-align: top;" valign=top> <td style="width: 50%; padding-right: 10px; padding-left: 10px; border-right-style: None; border-left-style: None; border-top-style: None; border-bottom-style: None;" width=50%> <p style="font-family: Arial;"><small style="font-size: smaller;">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -