|
1 /* |
|
2 * Copyright (c) 2002 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 * Methods for Phonebook Contact editor date field. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkContactEditorDateField.h" |
|
22 #include "TPbkContactItemField.h" |
|
23 #include "MPbkContactEditorUiBuilder.h" |
|
24 #include "MPbkFieldEditorVisitor.h" |
|
25 |
|
26 #include <CPbkContactItem.h> |
|
27 |
|
28 #include <e32base.h> |
|
29 #include <eikmfne.h> |
|
30 #include <barsread.h> |
|
31 #include <coemain.h> |
|
32 #include <eikcapc.h> |
|
33 |
|
34 #include <PbkView.rsg> |
|
35 |
|
36 |
|
37 /// Unnamed namespace for local definitons |
|
38 namespace { |
|
39 |
|
40 // LOCAL CONSTANTS AND MACROS |
|
41 |
|
42 #ifdef _DEBUG |
|
43 /// Panic codes for CPbkContactEditorDateField |
|
44 enum TPanicCode |
|
45 { |
|
46 EPanicPreCond_InitControlL, |
|
47 EPanicPreCond_SaveFieldL, |
|
48 EPanicPostCond_SaveFieldL |
|
49 }; |
|
50 |
|
51 void Panic(TPanicCode aReason) |
|
52 { |
|
53 _LIT(KPanicText, "CPbkContactEditorDateField"); |
|
54 User::Panic(KPanicText, aReason); |
|
55 } |
|
56 #endif // _DEBUG |
|
57 |
|
58 } // namespace |
|
59 |
|
60 |
|
61 // ================= MEMBER FUNCTIONS ======================= |
|
62 |
|
63 inline CPbkContactEditorDateField::CPbkContactEditorDateField |
|
64 (TPbkContactItemField& aField, |
|
65 CPbkIconInfoContainer& aIconInfoContainer, |
|
66 MPbkContactEditorUiBuilder& aUiBuilder) : |
|
67 CPbkContactEditorFieldBase(aField, aIconInfoContainer, aUiBuilder) |
|
68 { |
|
69 } |
|
70 |
|
71 inline void CPbkContactEditorDateField::ConstructL() |
|
72 { |
|
73 __ASSERT_DEBUG(ContactItemField().StorageType() == KStorageTypeDateTime, |
|
74 Panic(EPanicPreCond_InitControlL)); |
|
75 |
|
76 iControl = static_cast<CEikDateEditor*>(iUiBuilder.CreateLineL( |
|
77 ContactItemField().Label(), ControlId(), EEikCtDateEditor)); |
|
78 |
|
79 // ctrl is now owned by the dialog |
|
80 TResourceReader reader; |
|
81 CCoeEnv::Static()->CreateResourceReaderLC(reader, R_PBK_EDITOR_DATE_SETTINGS); |
|
82 iControl->ConstructFromResourceL(reader); |
|
83 CleanupStack::PopAndDestroy(); // R_PBK_EDITOR_DATE_SETTINGS |
|
84 |
|
85 TTime time = ContactItemField().DateTimeStorage()->Time(); |
|
86 if (time == Time::NullTTime()) |
|
87 { |
|
88 time.HomeTime(); |
|
89 } |
|
90 |
|
91 iControl->SetDate(time); |
|
92 |
|
93 // Postcond ceased to work, maybe CEikDateEditor clips the time of the day part? |
|
94 // __ASSERT_DEBUG(aCtrl->Date() == aField.DateTimeStorage()->Time(), Panic(EPanicPostCond_InitControlL)); |
|
95 |
|
96 LoadBitmapToFieldL(iUiBuilder); |
|
97 iCaptionedCtrl = iUiBuilder.LineControl(ControlId()); |
|
98 iUiBuilder.SetEditableL(ETrue); |
|
99 } |
|
100 |
|
101 CPbkContactEditorDateField* CPbkContactEditorDateField::NewL |
|
102 (TPbkContactItemField& aField, |
|
103 MPbkContactEditorUiBuilder& aUiBuilder, |
|
104 CPbkIconInfoContainer& aIconInfoContainer) |
|
105 { |
|
106 CPbkContactEditorDateField* self = new(ELeave) CPbkContactEditorDateField( |
|
107 aField, aIconInfoContainer, aUiBuilder); |
|
108 CleanupStack::PushL(self); |
|
109 self->ConstructL(); |
|
110 CleanupStack::Pop(self); |
|
111 return self; |
|
112 } |
|
113 |
|
114 CPbkContactEditorDateField::~CPbkContactEditorDateField() |
|
115 { |
|
116 } |
|
117 |
|
118 void CPbkContactEditorDateField::SaveFieldL() |
|
119 { |
|
120 // PreCond: |
|
121 __ASSERT_DEBUG(iControl && Field().StorageType() == KStorageTypeDateTime, |
|
122 Panic(EPanicPreCond_SaveFieldL)); |
|
123 |
|
124 iContactDataHasChanged = EFalse; |
|
125 |
|
126 // fetch the date from the date control |
|
127 const TTime dateTime = iControl->Date(); |
|
128 if (Field().DateTimeStorage()->Time() != dateTime) |
|
129 { |
|
130 // put the date in the contact item |
|
131 Field().DateTimeStorage()->SetTime(dateTime); |
|
132 Field().SetHidden(EFalse); |
|
133 iContactDataHasChanged = ETrue; |
|
134 } |
|
135 |
|
136 //PostCond: |
|
137 __ASSERT_DEBUG(Field().DateTimeStorage()->Time() == dateTime && |
|
138 !Field().IsHidden(), |
|
139 Panic(EPanicPostCond_SaveFieldL)); |
|
140 } |
|
141 |
|
142 void CPbkContactEditorDateField::AddFieldL(CPbkContactItem& aContact) |
|
143 { |
|
144 const TTime dateTime = iControl->Date(); |
|
145 TPbkContactItemField* field = aContact.AddOrReturnUnusedFieldL |
|
146 ( Field().FieldInfo() ); |
|
147 if (field) |
|
148 { |
|
149 field->DateTimeStorage()->SetTime(dateTime); |
|
150 } |
|
151 } |
|
152 |
|
153 HBufC* CPbkContactEditorDateField::ControlTextL() const |
|
154 { |
|
155 return NULL; |
|
156 } |
|
157 |
|
158 void CPbkContactEditorDateField::ActivateL() |
|
159 { |
|
160 iCaptionedCtrl->ActivateL(); |
|
161 } |
|
162 |
|
163 void CPbkContactEditorDateField::AcceptL(MPbkFieldEditorVisitor& aVisitor) |
|
164 { |
|
165 aVisitor.VisitL(*this); |
|
166 } |
|
167 |
|
168 // End of File |