src/corelib/kernel/qcore_symbian_p.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
child 18 2f34d5167611
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtCore module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <exception>
       
    43 #include <e32base.h>
       
    44 #include <e32uid.h>
       
    45 #include "qcore_symbian_p.h"
       
    46 #include <string>
       
    47 
       
    48 QT_BEGIN_NAMESPACE
       
    49 
       
    50 /*
       
    51     Helper function for calling into Symbian classes that expect a TDes&.
       
    52     This function converts a QString to a TDes by allocating memory that
       
    53     must be deleted by the caller.
       
    54 */
       
    55 
       
    56 Q_CORE_EXPORT HBufC* qt_QString2HBufC(const QString& aString)
       
    57 {
       
    58     HBufC *buffer;
       
    59 #ifdef QT_NO_UNICODE
       
    60     TPtrC8 ptr(reinterpret_cast<const TUint8*>(aString.toLocal8Bit().constData()));
       
    61 #else
       
    62     TPtrC16 ptr(qt_QString2TPtrC(aString));
       
    63 #endif
       
    64     buffer = q_check_ptr(HBufC::New(ptr.Length()));
       
    65     buffer->Des().Copy(ptr);
       
    66     return buffer;
       
    67 }
       
    68 
       
    69 Q_CORE_EXPORT QString qt_TDesC2QString(const TDesC& aDescriptor)
       
    70 {
       
    71 #ifdef QT_NO_UNICODE
       
    72     return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length());
       
    73 #else
       
    74     return QString::fromUtf16(aDescriptor.Ptr(), aDescriptor.Length());
       
    75 #endif
       
    76 }
       
    77 
       
    78 QHBufC::QHBufC()
       
    79     : m_hBufC(0)
       
    80 {
       
    81 }
       
    82 
       
    83 QHBufC::QHBufC(const QHBufC &src)
       
    84 	: m_hBufC(q_check_ptr(src.m_hBufC->Alloc()))
       
    85 {
       
    86 }
       
    87 
       
    88 /*!
       
    89   \internal
       
    90   Constructs a QHBufC from an HBufC. Note that the QHBufC instance takes
       
    91   ownership of the HBufC.
       
    92 */
       
    93 QHBufC::QHBufC(HBufC *src)
       
    94     : m_hBufC(src)
       
    95 {
       
    96 }
       
    97 
       
    98 QHBufC::QHBufC(const QString &src)
       
    99 {
       
   100     m_hBufC = qt_QString2HBufC(src);
       
   101 }
       
   102 
       
   103 QHBufC::~QHBufC()
       
   104 {
       
   105     if (m_hBufC)
       
   106         delete m_hBufC;
       
   107 }
       
   108 
       
   109 class QS60PluginResolver
       
   110 {
       
   111 public:
       
   112     QS60PluginResolver()
       
   113         : initTried(false) {}
       
   114 
       
   115     ~QS60PluginResolver() {
       
   116         lib.Close();
       
   117     }
       
   118 
       
   119     TLibraryFunction resolve(int ordinal) {
       
   120         if (!initTried) {
       
   121             init();
       
   122             initTried = true;
       
   123         }
       
   124 
       
   125         if (lib.Handle())
       
   126             return lib.Lookup(ordinal);
       
   127         else
       
   128             return reinterpret_cast<TLibraryFunction>(NULL);
       
   129     }
       
   130 
       
   131 private:
       
   132     void init()
       
   133     {
       
   134 #ifdef Q_WS_S60
       
   135         _LIT(KLibName_3_1, "qts60plugin_3_1.dll");
       
   136         _LIT(KLibName_3_2, "qts60plugin_3_2.dll");
       
   137         _LIT(KLibName_5_0, "qts60plugin_5_0.dll");
       
   138         TPtrC libName;
       
   139         TInt uidValue;
       
   140         switch (QSysInfo::s60Version()) {
       
   141         case QSysInfo::SV_S60_3_1:
       
   142             libName.Set(KLibName_3_1);
       
   143             uidValue = 0x2001E620;
       
   144             break;
       
   145         case QSysInfo::SV_S60_3_2:
       
   146             libName.Set(KLibName_3_2);
       
   147             uidValue = 0x2001E621;
       
   148             break;
       
   149         case QSysInfo::SV_S60_5_0: // Fall through to default
       
   150         default:
       
   151             // Default to 5.0 version, as any unknown platform is likely to be newer than that
       
   152             libName.Set(KLibName_5_0);
       
   153             uidValue = 0x2001E622;
       
   154             break;
       
   155         }
       
   156 
       
   157         TUidType libUid(KDynamicLibraryUid, KSharedLibraryUid, TUid::Uid(uidValue));
       
   158         lib.Load(libName, libUid);
       
   159 #endif
       
   160     }
       
   161 
       
   162     RLibrary lib;
       
   163     bool initTried;
       
   164 };
       
   165 
       
   166 Q_GLOBAL_STATIC(QS60PluginResolver, qt_s60_plugin_resolver);
       
   167 
       
   168 /*!
       
   169   \internal
       
   170   Resolves a platform version specific function from S60 plugin.
       
   171   If plugin is missing or resolving fails for another reason, NULL is returned.
       
   172 */
       
   173 Q_CORE_EXPORT TLibraryFunction qt_resolveS60PluginFunc(int ordinal)
       
   174 {
       
   175     return qt_s60_plugin_resolver()->resolve(ordinal);
       
   176 }
       
   177 
       
   178 class QS60RFsSession
       
   179 {
       
   180 public:
       
   181     QS60RFsSession() {
       
   182         qt_symbian_throwIfError(iFs.Connect());
       
   183         qt_symbian_throwIfError(iFs.ShareProtected());
       
   184     }
       
   185 
       
   186     ~QS60RFsSession() {
       
   187         iFs.Close();
       
   188     }
       
   189 
       
   190     RFs& GetRFs() {
       
   191         return iFs;
       
   192     }
       
   193 
       
   194 private:
       
   195 
       
   196     RFs iFs;
       
   197 };
       
   198 
       
   199 Q_GLOBAL_STATIC(QS60RFsSession, qt_s60_RFsSession);
       
   200 
       
   201 Q_CORE_EXPORT RFs& qt_s60GetRFs()
       
   202 {
       
   203     return qt_s60_RFsSession()->GetRFs();
       
   204 }
       
   205 
       
   206 QT_END_NAMESPACE