|
1 /* |
|
2 * Copyright (c) 2010 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 "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: |
|
15 * Certificate information data structure for EAP QT configuration interface |
|
16 * |
|
17 */ |
|
18 |
|
19 /* |
|
20 * %version: 3 % |
|
21 */ |
|
22 |
|
23 #include "eapqtcertificateinfo.h" |
|
24 #include <QDebug> |
|
25 class EapQtCertificateInfoPrivate |
|
26 { |
|
27 friend class EapQtCertificateInfo; |
|
28 public: |
|
29 |
|
30 EapQtCertificateInfoPrivate() {}; |
|
31 ~EapQtCertificateInfoPrivate() {}; |
|
32 |
|
33 // copy constructor |
|
34 EapQtCertificateInfoPrivate(const EapQtCertificateInfoPrivate &certInfo) |
|
35 { |
|
36 mCerts = certInfo.mCerts; |
|
37 } |
|
38 |
|
39 QVariant value(int id); |
|
40 void setValue(int id, QVariant newValue); |
|
41 |
|
42 private: |
|
43 // disable assignment |
|
44 EapQtCertificateInfoPrivate &operator=(const EapQtCertificateInfoPrivate&); |
|
45 QHash<int, QVariant> mCerts; |
|
46 |
|
47 }; |
|
48 |
|
49 |
|
50 //---------------------------------------------------------------------------- |
|
51 // EapQtCertificateInfo |
|
52 //---------------------------------------------------------------------------- |
|
53 |
|
54 |
|
55 EapQtCertificateInfo::EapQtCertificateInfo() : |
|
56 d_ptr(new EapQtCertificateInfoPrivate) |
|
57 { |
|
58 } |
|
59 |
|
60 EapQtCertificateInfo::~EapQtCertificateInfo() |
|
61 { |
|
62 // scoped pointer deleted automatically |
|
63 } |
|
64 |
|
65 EapQtCertificateInfo::EapQtCertificateInfo(const EapQtCertificateInfo &certInfo) : |
|
66 d_ptr(new EapQtCertificateInfoPrivate(*(certInfo.d_ptr))) |
|
67 { |
|
68 } |
|
69 |
|
70 EapQtCertificateInfo& EapQtCertificateInfo::operator=(const EapQtCertificateInfo &certInfo) |
|
71 { |
|
72 // check if assigning to myself |
|
73 if (this != &certInfo) { |
|
74 d_ptr.reset(new EapQtCertificateInfoPrivate(*(certInfo.d_ptr))); |
|
75 } |
|
76 return *this; |
|
77 } |
|
78 |
|
79 QVariant EapQtCertificateInfo::value(const ItemId id) const |
|
80 { |
|
81 // check for valid range, otherwise memory is consumed for no reason |
|
82 if(id >= ItemIdLast) { |
|
83 qDebug("ERROR: EapQtCertificateInfo::value - invalid id!"); |
|
84 return QVariant::Invalid; |
|
85 } |
|
86 return d_ptr->mCerts[id]; |
|
87 } |
|
88 |
|
89 void EapQtCertificateInfo::setValue(const ItemId id, const QVariant &newValue) |
|
90 { |
|
91 // check for valid range, otherwise memory is consumed for no reason |
|
92 if(id < ItemIdLast) { |
|
93 d_ptr->mCerts[id] = newValue; |
|
94 } else { |
|
95 qDebug("ERROR: EapQtCertificateInfo::setValue - invalid id!"); |
|
96 } |
|
97 return; |
|
98 } |
|
99 |
|
100 bool EapQtCertificateInfo::operator==(const EapQtCertificateInfo & rhs ) const |
|
101 { |
|
102 bool ret = true; |
|
103 if (d_ptr->mCerts.size() != rhs.d_ptr->mCerts.size()) { |
|
104 qWarning("EapQtCertificateInfo::operator==(): size: expect %d, actual %d ", |
|
105 d_ptr->mCerts.size(), |
|
106 rhs.d_ptr->mCerts.size() ); |
|
107 ret = false; |
|
108 } |
|
109 QHashIterator<int, QVariant> i(d_ptr->mCerts); |
|
110 |
|
111 while (i.hasNext()) { |
|
112 i.next(); |
|
113 if (!rhs.d_ptr->mCerts.contains(i.key())){ |
|
114 qWarning("EapQtCertificateInfo::operator==(): key not found: %d", i.key()); |
|
115 ret = false; |
|
116 |
|
117 } |
|
118 if (i.value() != rhs.d_ptr->mCerts[i.key()]){ |
|
119 qWarning("EapQtCertificateInfo::operator==(): values not match"); |
|
120 qDebug() << "Expect: " << i.value(); |
|
121 qDebug() << "Actual: " << i.value(); |
|
122 ret = false; |
|
123 } |
|
124 } |
|
125 return ret; |
|
126 } |