|
1 /* |
|
2 * Copyright (c) 2002-2007 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 * Phonebook 2 default saving store monitor. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbk2DefaultSavingStoreMonitor.h" |
|
22 |
|
23 // From Phonebook2 |
|
24 #include <Phonebook2InternalCRKeys.h> |
|
25 #include <MPbk2DefaultSavingStoreObserver.h> |
|
26 |
|
27 // From Virtual phonebook |
|
28 #include <TVPbkContactStoreUriPtr.h> |
|
29 |
|
30 // From System |
|
31 #include <centralrepository.h> |
|
32 |
|
33 // Unnamed namespace for local definitions |
|
34 namespace { |
|
35 |
|
36 // Definition for initial store uri size |
|
37 const TInt KInitialStoreUriSize = 1; |
|
38 |
|
39 }// namespace |
|
40 |
|
41 |
|
42 // ================= MEMBER FUNCTIONS ======================= |
|
43 |
|
44 // -------------------------------------------------------------------------- |
|
45 // CPbk2DefaultSavingStoreMonitor::CPbk2DefaultSavingStoreMonitor |
|
46 // -------------------------------------------------------------------------- |
|
47 // |
|
48 CPbk2DefaultSavingStoreMonitor::CPbk2DefaultSavingStoreMonitor( |
|
49 CRepository& aRepository, |
|
50 MPbk2DefaultSavingStoreObserver& aObserver ) : |
|
51 CActive(EPriorityHigh), |
|
52 iRepository(aRepository), |
|
53 iObserver( aObserver ) |
|
54 { |
|
55 CActiveScheduler::Add(this); |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CPbk2DefaultSavingStoreMonitor::~CPbk2DefaultSavingStoreMonitor |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 CPbk2DefaultSavingStoreMonitor::~CPbk2DefaultSavingStoreMonitor() |
|
63 { |
|
64 Cancel(); |
|
65 delete iDefaultStoreUri; |
|
66 } |
|
67 |
|
68 // -------------------------------------------------------------------------- |
|
69 // CPbk2DefaultSavingStoreMonitor::NewL |
|
70 // -------------------------------------------------------------------------- |
|
71 // |
|
72 CPbk2DefaultSavingStoreMonitor* CPbk2DefaultSavingStoreMonitor::NewL( |
|
73 CRepository& aRepository, MPbk2DefaultSavingStoreObserver& aObserver) |
|
74 { |
|
75 CPbk2DefaultSavingStoreMonitor* self = |
|
76 new(ELeave) CPbk2DefaultSavingStoreMonitor(aRepository, aObserver); |
|
77 CleanupStack::PushL(self); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop(self); |
|
80 return self; |
|
81 } |
|
82 |
|
83 // -------------------------------------------------------------------------- |
|
84 // CPbk2DefaultSavingStoreMonitor::ConstructL |
|
85 // -------------------------------------------------------------------------- |
|
86 // |
|
87 inline void CPbk2DefaultSavingStoreMonitor::ConstructL() |
|
88 { |
|
89 RenewRequestL(); |
|
90 } |
|
91 |
|
92 // -------------------------------------------------------------------------- |
|
93 // CPbk2DefaultSavingStoreMonitor::DefaultSavingStoreL |
|
94 // -------------------------------------------------------------------------- |
|
95 // |
|
96 TVPbkContactStoreUriPtr |
|
97 CPbk2DefaultSavingStoreMonitor::DefaultSavingStoreL() const |
|
98 { |
|
99 if ( !iDefaultStoreUri ) |
|
100 { |
|
101 iDefaultStoreUri = UpdateDefaultSavingStoreL(); |
|
102 } |
|
103 return *iDefaultStoreUri; |
|
104 } |
|
105 |
|
106 // -------------------------------------------------------------------------- |
|
107 // CPbk2DefaultSavingStoreMonitor::UpdateDefaultSavingStoreL |
|
108 // -------------------------------------------------------------------------- |
|
109 // |
|
110 HBufC* CPbk2DefaultSavingStoreMonitor::UpdateDefaultSavingStoreL() const |
|
111 { |
|
112 HBufC* defaultStoreUri = HBufC::NewL(KInitialStoreUriSize); |
|
113 TPtr ptr = defaultStoreUri->Des(); |
|
114 TInt actualSize = 0; |
|
115 TInt ret = iRepository.Get |
|
116 (KPhonebookDefaultSavingStoreUri, ptr, actualSize); |
|
117 if (ret == KErrOverflow) |
|
118 { |
|
119 delete defaultStoreUri; |
|
120 defaultStoreUri = NULL; |
|
121 defaultStoreUri = HBufC::NewL(actualSize); |
|
122 CleanupStack::PushL( defaultStoreUri ); |
|
123 ptr.Set(defaultStoreUri->Des()); |
|
124 User::LeaveIfError(iRepository.Get |
|
125 (KPhonebookDefaultSavingStoreUri, ptr)); |
|
126 CleanupStack::Pop( defaultStoreUri ); |
|
127 } |
|
128 return defaultStoreUri; |
|
129 } |
|
130 |
|
131 // -------------------------------------------------------------------------- |
|
132 // CPbk2DefaultSavingStoreMonitor::RenewRequestL |
|
133 // -------------------------------------------------------------------------- |
|
134 // |
|
135 void CPbk2DefaultSavingStoreMonitor::RenewRequestL() |
|
136 { |
|
137 User::LeaveIfError(iRepository.NotifyRequest( |
|
138 KPhonebookDefaultSavingStoreUri, iStatus)); |
|
139 SetActive(); |
|
140 } |
|
141 |
|
142 // -------------------------------------------------------------------------- |
|
143 // CPbk2DefaultSavingStoreMonitor::RunL |
|
144 // -------------------------------------------------------------------------- |
|
145 // |
|
146 void CPbk2DefaultSavingStoreMonitor::RunL() |
|
147 { |
|
148 HBufC* temp = UpdateDefaultSavingStoreL(); |
|
149 delete iDefaultStoreUri; |
|
150 iDefaultStoreUri = NULL; |
|
151 iDefaultStoreUri = temp; |
|
152 iObserver.SavingStoreChanged(); |
|
153 RenewRequestL(); |
|
154 } |
|
155 |
|
156 // -------------------------------------------------------------------------- |
|
157 // CPbk2DefaultSavingStoreMonitor::DoCancel |
|
158 // -------------------------------------------------------------------------- |
|
159 // |
|
160 void CPbk2DefaultSavingStoreMonitor::DoCancel() |
|
161 { |
|
162 iRepository.NotifyCancelAll(); |
|
163 } |
|
164 |
|
165 // End of File |