chxavutil.h
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:10k
- /*****************************************************************************
- * chxavutil.h
- * --------------
- *
- * Synopsis:
- * URL Utility namespace.
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *****************************************************************************/
- #ifndef _chxavutil_h_
- #define _chxavutil_h_
- // Symbian includes...
- #include <aknpopup.h>
- #include <akntitle.h>
- #include <eikenv.h>
- #include <coemain.h>
- //#include "hlxclib/string.h"
- // Helix includes...
- #include "hxtypes.h"
- #include "hxassert.h"
- #include "unkimp.h"
- #include "ihxpckts.h"
- #include "hxstring.h"
- #include "hxurl.h"
- // Includes from this project...
- #include "realplayer.rsg"
- #include "chxavstringutils.h"
- #include "chxavvector.h"
- #include "chxavstringutils.h"
- #include "chxavcleanupstack.h"
- #include "chxavmessagedialog.h"
- #include "chxavurlrep.h"
- namespace CHXAvUtil {
- // constants
- //
- // file urls take form "file://<host>/<path>"; we are supplying empty string for <host>
- _LIT(KFileProtocolPrefix, "file:///");
- _LIT(KRTSPProtocolPrefix, "rtsp://");
- const TUint k_cchMaxTimerText = 20; // more than enough for 0000:00:00
- //
- // functions
- //
- CHXString ExtractFilename(const CHXString& path);
- void BackToForwardSlash(TPtr& ptr);
- void ForwardToBackSlash(TPtr& ptr);
- TPtrC PathFromFileURL(const TDesC& fileURL);
- HBufC* AllocStdPathFromPlayerUrlL(const CHXString& strBadPath);
- HBufC* AllocStdPathFromPlayerUrlL(const TDesC& epURL);
- HBufC* AllocHostFromPlayerUrlL(const CHXString& strUrl);
- HBufC* AllocDisplayTextForPlayerUrlL(const TDesC& url, bool bHideExt = true);
- void ActiveWait(TInt msTotalWait, TInt msPerSleep = 20);
- enum ValidateUrlResult
- {
- vuGood,
- vuBad,
- vuEmpty,
- vuMissingScheme,
- vuUnsupportedScheme,
- vuHostUnexpected,
- vuMissingHost,
- vuMissingPath,
- vuMissingFile
- };
- ValidateUrlResult ValidateUrl(const TDesC& url);
- TInt ScanPastURLSchemePrefix(const TDesC& url);
- bool HasValidURLSchemePrefix(const TDesC& url); // '{scheme}:'
- bool HasValidNetworkURLSchemePrefix(const TDesC& url); // '{scheme}://'
- ///////////////////////////////////
- //
- template<TInt size>
- inline
- TInt litSize(const TLitC<size>&)
- {
- return size - 1;
- }
- //
- // inlines
- //
- inline
- bool IsFileUrl(const TDesC& url)
- {
- TPtrC ptr(url.Left(litSize(KFileProtocolPrefix)));
- return (0 == ptr.CompareF(KFileProtocolPrefix));
- }
- inline
- bool IsLocal(const TDesC& url)
- {
- return IsFileUrl(url);
- }
- inline
- bool IsFileUrl(const char* pszUrl)
- {
- return (0 == strnicmp(pszUrl, "file://", 7));
- }
- inline
- bool IsHttpUrl(const char* pszUrl)
- {
- return (0 == strnicmp(pszUrl, "http://", 7));
- }
- inline
- bool IsLocal(const char* pszUrl)
- {
- return IsFileUrl(pszUrl);
- }
- inline bool IsValidUrl(const TDesC& url)
- {
- return (vuGood == ValidateUrl(url));
- }
- // return true if url prefix matches "{scheme}:"
- inline
- bool HasValidURLSchemePrefix(const TDesC& url)
- {
- return (-1 != ScanPastURLSchemePrefix(url));
- }
- ////////////////////////////////////////
- // utVector helper
- template< typename T >
- inline
- void Append( CHXAvVector<T>& vec, const T& val)
- {
- int n = vec.Nelements();
- vec.Resize(n+1);
- vec[n] = val;
- }
- ////////////////////////////////////////////////////////////
- //
- inline
- void BackToForwardSlash(TPtr& ptr)
- {
- CHXAvStringUtils::Replace(ptr, '\', '/');
- }
- ////////////////////////////////////////////////////////////
- //
- inline
- void ForwardToBackSlash(TPtr& ptr)
- {
- CHXAvStringUtils::Replace(ptr, '/', '\');
- }
- ///////////////////////////////////////////////////////////////
- // types, typedefs
- //
- // multiple return value
- template< typename T >
- struct Pair
- {
- T first;
- T second;
- };
- ///////////////////////////////////////////////////////////////
- // contants
- //
- // relative to player app folder
- _LIT(KPlayerDataFolder, "data\");
- _LIT(KImagesMBMName, "realplayer.mbm");
- // relative to player data folder
- _LIT(KRecentClipsName, "recent.inf");
- _LIT(KPluginArchiveName, "plugin_archive.txt");
- _LIT(KEPSystemFolderName, "\system\");
- _LIT(KPathSep, "\");
- _LIT(KLinkFileExt, ".ram");
- _LIT(KDot, ".");
- _LIT(KDoubleDot, "..");
- _LIT(KNewline, "n");
- #if defined(_UNICODE)
- //note: text control inserts unicode paragraph sep for return key
- //0x2028 line separator
- //0x2029 paragraph separator
- _LIT(KStdWhitespaceCtrlChars, "ntrx2028x2029");
- #else
- _LIT(KStdWhitespaceCtrlChars, "ntr");
- #endif
- // TWsEvent for inter-app (instance to instance) messaging
- const TUint KHXPlayerWsEvent = EEventUser + 0x9D06; // arbitrary - uniqueness likely but not guaranteed
- // message text sent to other r1p instances
- _LIT8(KMessage_CloseApp, "close_app");
- //
- // misc values
- //
- // minimum amount of memory needed to complete an Add To Pinboard
- const TInt KMinAddToPinboardMem=32*1024;
- // This value determines how much each file will be read and passed
- // to the recognizer. The larger the buffer, the better chance of
- // recognition, however, larger buffers have a performance impact.
- // Like so many other things, it's a tradeoff.
- const TInt KRecogLength=512;
- const TInt KDefaultRecentClipListCount = 6;
- // time constants
- const TUint k_usecPerMs = 1000;
- const TUint k_msPerSecond = 1000;
- const TUint k_usecPerSecond = k_msPerSecond * k_usecPerMs;
- const TUint k_secsPerHour = 3600;
- const TUint k_secsPerMin = 60;
- const TUint k_msPerHour = k_secsPerHour * k_msPerSecond;
- const TUint k_bytesPerKilobyte = 1024;
- const TUint k_bitrateBytesPer1k = 1000;
- // max chars needed to display an integer number
- const TUint KMaxInt32Chars = 10;
- const TUint KMaxDoubleChars = 20; // long double = 19 actually
- // EP-specific error codes (Symbian errors are negative values)
- const TInt KEPErrBase = 50;
- const TInt KEPControlAlreadyExists = KEPErrBase + 1;
- const TInt KEPBadControlID = KEPErrBase + 2;
- const TInt KEPMissingSkinControls = KEPErrBase + 3;
- ///////////////////////////////////
- // return true if entry should be hidden from the user
- inline
- bool ShouldHideFromUser(const TEntry& entry)
- {
- // note: this does not seem to be report systeam attribute
- // for system dir on Series60 (c.f. BaflUtils::RemoveSystemDirectory() )
- return (entry.IsHidden() || entry.IsSystem());
- }
- ////////////////////////////////////////////////
- // copy 16 bit buffer to 8 bit
- inline
- void Copy8( TDesC16& text, TDes8& out)
- {
- out.Copy( reinterpret_cast<const TUint8*>(text.Ptr()), text.Size());
- }
- ///////////////////////////////////
- //
- inline
- int PointsToTwips(int points)
- {
- return points * 20;
- }
- //
- // unicode/ansi text macros
- //
- // don't use these directly; see below
- #define WTEXT__(str) (L ## str)
- #define ATEXT__(str) (str)
- // use these; expands str first cpp pass, e.g., handles WTEXT(__FILE__)
- #define WTEXT(str) WTEXT__(str) // make wide (unicode)
- #define ATEXT(str) ATEXT__(str) // make ansi
- #if defined(_UNICODE)
- #define TEXT(a) WTEXT__(a)
- typedef wchar_t TCHAR;
- #else
- #define TEXT__(a) ATEXT__(a)
- typedef char TCHAR;
- #endif
- // ez lookup table helpers
- //
- // 1) create table
- // static const epUtil::KeyValEntry<TUint, const TCHAR*> myTable[] = { Emit_(FOO), ... }
- //
- // 2) lookup
- // val = epUtil::DoLookup(myTable, ARRAY_COUNT(myTable), someKey);
- //
- // stringify val as: depends on _UNICODE defined; ansi; or wide(unicode)
- #define Emit_(x) { x, TEXT(#x) }
- #define EmitA_(x) { x, ATEXT(#x) }
- #define EmitW_(x) { x, WTEXT(#x) }
- // simple one-to-one look up table entry for DoLookup
- template<typename KeyType_, typename ValType_>
- struct KeyValEntry
- {
- typedef KeyType_ KeyType;
- typedef ValType_ ValType;
- KeyType_ key;
- ValType_ val;
- };
- template<typename T>
- struct CompareTrait
- {
- static bool Compare(const T& left, const T& right) { return (left == right); }
- };
- template<>
- struct CompareTrait<const char*>
- {
- static bool Compare(const char* left, const char* right) { return (0 == strcmp(left,right)); }
- };
- ////////////////////////////////////////////////
- // Do simple one-to-one table look up
- template <typename EntryType>
- typename EntryType::ValType DoLookup(EntryType* pTable, TUint count,
- typename EntryType::KeyType key )
- {
- typedef typename EntryType::ValType ValType;
- typedef typename EntryType::KeyType KeyType;
- // return default constructed object by default
- ValType val = ValType();
- for(TUint idx = 0; idx < count; ++idx )
- {
- if(CompareTrait<KeyType>::Compare(key, pTable[idx].key))
- {
- val = pTable[idx].val;
- break;
- }
- }
- return val;
- }
- ////////////////////////////////////////////////
- // given ordered array of items (valArray),
- // returns nearest index that input value (val)
- // matches or exceeds
- //
- // e.g., for:
- //
- // int vals[] = { 12, 100, 530, 999 }
- //
- // you get:
- //
- // val return
- // --------------
- // 9 0
- // 100 1
- // 529 1
- // 999 3
- // 1000 3
- //
- //
- template< typename T >
- TInt GetThresholdIndex(T val, const T valArray[], TInt count)
- {
- T bestMatch = 0;
- TInt idxBestMatch = count - 1;
- for( TInt idx = 0; idx < count; ++idx )
- {
- bestMatch = valArray[idx];
- if( bestMatch > val )
- {
- // return next lowest (be conservative), or lowest
- idxBestMatch = max(idx - 1, 0);
- break;
- }
- }
- return idxBestMatch;
- }
- }
- using namespace CHXAvUtil;
- #endif // _chxavutil_h_