src/hbcore/devicedialogbase/hbsymbianvariantconverter.cpp
changeset 34 ed14f46c0e55
parent 0 16d8024aca5e
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    28 #include <QRect>
    28 #include <QRect>
    29 
    29 
    30 #include "hbsymbianvariantconverter_p.h"
    30 #include "hbsymbianvariantconverter_p.h"
    31 #include "hbsymbianvariant.h"
    31 #include "hbsymbianvariant.h"
    32 
    32 
       
    33 _LIT(KPanicDeviceDialogNotSupportedType, "CHbDeviceDialog: Not supported type");
       
    34 
    33 void HbSymbianVariantConverter::toQtVariant(const CHbSymbianVariant* source, 
    35 void HbSymbianVariantConverter::toQtVariant(const CHbSymbianVariant* source, 
    34                                             QVariant& result )
    36                                             QVariant& result )
    35 {
    37 {
    36     if (!source) {
    38     if (!source) {
    37         result.clear();
    39         result.clear();
   102         break;
   104         break;
   103         case CHbSymbianVariant::EDesArray:
   105         case CHbSymbianVariant::EDesArray:
   104         {
   106         {
   105             CDesC16ArrayFlat* srcArray = source->Value<CDesC16ArrayFlat>();
   107             CDesC16ArrayFlat* srcArray = source->Value<CDesC16ArrayFlat>();
   106             QStringList stringList;
   108             QStringList stringList;
   107             for(TInt i = 0; i < srcArray->MdcaCount(); i++) {
   109             for (TInt i = 0; i < srcArray->MdcaCount(); ++i) {
   108                 stringList.append(QString::fromUtf16(srcArray->MdcaPoint(i).Ptr(), srcArray->MdcaPoint(i).Length()));
   110                 stringList.append(QString::fromUtf16(srcArray->MdcaPoint(i).Ptr(), srcArray->MdcaPoint(i).Length()));
   109             }
   111             }
   110             result.setValue(stringList);
   112             result.setValue(stringList);
   111         }
   113         }
   112         break;
   114         break;
   128 
   130 
   129 void HbSymbianVariantConverter::toQtVariantMap(const CHbSymbianVariantMap &aSymbianVariantMap, 
   131 void HbSymbianVariantConverter::toQtVariantMap(const CHbSymbianVariantMap &aSymbianVariantMap, 
   130                                                QVariantMap& aQvMap)
   132                                                QVariantMap& aQvMap)
   131 {
   133 {
   132     MDesCArray& keys = aSymbianVariantMap.Keys();
   134     MDesCArray& keys = aSymbianVariantMap.Keys();
   133     for(TInt i = 0; i < keys.MdcaCount() ; i++) {
   135     for (TInt i = 0; i < keys.MdcaCount() ; ++i) {
   134         TPtrC ptr = keys.MdcaPoint(i);
   136         TPtrC ptr = keys.MdcaPoint(i);
   135         QString key = QString::fromUtf16(ptr.Ptr(), ptr.Length());
   137         QString key = QString::fromUtf16(ptr.Ptr(), ptr.Length());
   136         QVariant variant;
   138         QVariant variant;
   137         toQtVariant(aSymbianVariantMap.Get(ptr), variant);
   139         toQtVariant(aSymbianVariantMap.Get(ptr), variant);
   138         aQvMap[key] = variant;
   140         aQvMap[key] = variant;
   207         break;
   209         break;
   208         case QVariant::StringList:
   210         case QVariant::StringList:
   209         {
   211         {
   210             QStringList stringList = aVariant.value<QStringList>();
   212             QStringList stringList = aVariant.value<QStringList>();
   211             QStringList::iterator i;
   213             QStringList::iterator i;
   212             CPtrCArray* descriptorArray = 0;
   214             CPtrCArray* descriptorArray = new (ELeave) CPtrCArray(stringList.count());
       
   215             CleanupStack::PushL(descriptorArray);
   213             for (i = stringList.begin(); i != stringList.end(); ++i) {
   216             for (i = stringList.begin(); i != stringList.end(); ++i) {
   214             descriptorArray = new CPtrCArray(stringList.count());
       
   215                 TPtrC listItem(static_cast<const TUint16*>((*i).utf16()),
   217                 TPtrC listItem(static_cast<const TUint16*>((*i).utf16()),
   216                         (*i).length());
   218                         (*i).length());
   217                 descriptorArray->AppendL(listItem);
   219                 descriptorArray->AppendL(listItem);
   218             }
   220             }
   219             MDesCArray* arrayInterface = static_cast<MDesCArray*>(descriptorArray);
   221             MDesCArray* arrayInterface = static_cast<MDesCArray*>(descriptorArray);
   220             return_value = CHbSymbianVariant::NewL(arrayInterface, CHbSymbianVariant::EDesArray);
   222             return_value = CHbSymbianVariant::NewL(arrayInterface, CHbSymbianVariant::EDesArray);
       
   223             CleanupStack::PopAndDestroy(descriptorArray);
   221         }
   224         }
   222         break;
   225         break;
   223         case QVariant::UInt:
   226         case QVariant::UInt:
   224         {
   227         {
   225             uint tempUint = aVariant.value<uint>();
   228             uint tempUint = aVariant.value<uint>();
   232             return_value = CHbSymbianVariant::NewL(fromQVariantMapL(map), CHbSymbianVariant::EVariantMap);
   235             return_value = CHbSymbianVariant::NewL(fromQVariantMapL(map), CHbSymbianVariant::EVariantMap);
   233         }
   236         }
   234         break;
   237         break;
   235         default:
   238         default:
   236         {
   239         {
   237             User::Panic(_L("CHbDeviceDialog: Not supported type"), aVariant.type());
   240             User::Panic(KPanicDeviceDialogNotSupportedType, aVariant.type());
   238         }
   241         }
   239         break;
   242         break;
   240     }
   243     }
   241     return return_value;
   244     return return_value;
   242 }
   245 }
   243 
   246 
   244 CHbSymbianVariantMap *HbSymbianVariantConverter::fromQVariantMapL(QVariantMap& aQvMap)
   247 CHbSymbianVariantMap *HbSymbianVariantConverter::fromQVariantMapL(QVariantMap& aQvMap)
   245 {
   248 {
   246     CHbSymbianVariantMap* map = CHbSymbianVariantMap::NewL();
   249     CHbSymbianVariantMap* map = CHbSymbianVariantMap::NewL();
       
   250     CleanupStack::PushL(map);
   247     QVariantMap::const_iterator i;
   251     QVariantMap::const_iterator i;
   248     for (i = aQvMap.constBegin(); i != aQvMap.constEnd(); ++i){
   252     for (i = aQvMap.constBegin(); i != aQvMap.constEnd(); ++i){
   249       QString keyString = i.key();
   253       QString keyString = i.key();
   250       TPtrC descriptor(static_cast<const TUint16*>(keyString.utf16()),
   254       TPtrC descriptor(static_cast<const TUint16*>(keyString.utf16()),
   251               i.key().length());
   255               i.key().length());
   252       QVariant value = i.value();
   256       QVariant value = i.value();
   253       CHbSymbianVariant* symbianVariant = fromQtVariantL(value);
   257       CHbSymbianVariant* symbianVariant = fromQtVariantL(value);
   254       map->Add(descriptor, symbianVariant);
   258       map->Add(descriptor, symbianVariant);
   255     }
   259     }
       
   260     CleanupStack::Pop(map);
   256     return map;
   261     return map;
   257 }
   262 }
   258 
   263