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: Home screen Backup/Restore observer. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <connect/sbdefs.h> |
|
19 #include "hsdatabase.h" |
|
20 #include "hsbackuprestoreobserver.h" |
|
21 #include "hsbackuprestoreactivecallback.h" |
|
22 |
|
23 using namespace conn; |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CHsBackupRestoreObserver::CHsBackupRestoreObserver |
|
27 // C++ default constructor |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CHsBackupRestoreObserver::CHsBackupRestoreObserver() : CActive(EPriorityNormal) |
|
31 { |
|
32 iLastType = conn::EBURUnset; |
|
33 iProperty.Attach(KUidSystemCategory, KUidBackupRestoreKey); |
|
34 CActiveScheduler::Add(this); |
|
35 iStatus = KRequestPending; |
|
36 iProperty.Subscribe(iStatus); |
|
37 SetActive(); |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CHsBackupRestoreObserver::ConstructL |
|
42 // S2nd phase constructor. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 void CHsBackupRestoreObserver::ConstructL() |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CSpaceDataStorageBURListener::NewL |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CHsBackupRestoreObserver* CHsBackupRestoreObserver::NewL() |
|
55 { |
|
56 CHsBackupRestoreObserver* self = new (ELeave) |
|
57 CHsBackupRestoreObserver(); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL( ); |
|
60 CleanupStack::Pop( self ); |
|
61 |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CHsBackupRestoreObserver::~CHsBackupRestoreObserver |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CHsBackupRestoreObserver::~CHsBackupRestoreObserver() |
|
70 { |
|
71 Cancel(); |
|
72 iProperty.Close(); |
|
73 delete iCallBack; |
|
74 delete iActiveBackupClient; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // Handles changes in backup state. |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CHsBackupRestoreObserver::HandleBackupStateL( const TInt aValue ) |
|
82 { |
|
83 const TInt type = aValue & conn::KBURPartTypeMask; |
|
84 |
|
85 // Test if the device is going into backup or restore mode, and we are |
|
86 // required to participate. |
|
87 if ( ( type == conn::EBURBackupFull || type == conn::EBURRestoreFull ) || |
|
88 ( type == conn::EBURBackupPartial || type == conn::EBURRestorePartial ) ) |
|
89 { |
|
90 if ( !iCallBack ) |
|
91 { |
|
92 iCallBack = CHsBRActiveCallback::NewL(); |
|
93 } |
|
94 |
|
95 if ( !iActiveBackupClient ) |
|
96 { |
|
97 iActiveBackupClient = conn::CActiveBackupClient::NewL( iCallBack ); |
|
98 |
|
99 if ( ( type == conn::EBURBackupPartial || |
|
100 type == conn::EBURRestorePartial ) && |
|
101 !iActiveBackupClient->DoesPartialBURAffectMeL() ) |
|
102 { |
|
103 delete iCallBack; |
|
104 iCallBack = NULL; |
|
105 delete iActiveBackupClient; |
|
106 iActiveBackupClient = NULL; |
|
107 return; |
|
108 } |
|
109 else if(type == conn::EBURRestorePartial || type == conn::EBURRestoreFull) |
|
110 { |
|
111 iCallBack->StartRestore(); |
|
112 } |
|
113 } |
|
114 |
|
115 iActiveBackupClient->ConfirmReadyForBURL( KErrNone ); |
|
116 } |
|
117 else |
|
118 { |
|
119 if ( type == conn::EBURNormal ) |
|
120 { |
|
121 if ( (iLastType == conn::EBURBackupFull || iLastType == conn::EBURBackupPartial) || |
|
122 (iLastType == conn::EBURRestorePartial || iLastType == conn::EBURRestoreFull) ) |
|
123 { |
|
124 iCallBack->FinishBackupRestore(); |
|
125 } |
|
126 // delete once back to normal. |
|
127 delete iCallBack; |
|
128 iCallBack = NULL; |
|
129 delete iActiveBackupClient; |
|
130 iActiveBackupClient = NULL; |
|
131 } |
|
132 } |
|
133 |
|
134 iLastType = type; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // Subsribes notifications of backup/restore p&s key. |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CHsBackupRestoreObserver::SubscribePSKey() |
|
142 { |
|
143 Cancel(); |
|
144 |
|
145 iProperty.Subscribe( iStatus ); |
|
146 SetActive(); |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CHsBackupRestoreObserver::DoCancel |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void CHsBackupRestoreObserver::DoCancel() |
|
154 { |
|
155 iProperty.Cancel( ); |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CHsBackupRestoreObserver::RunL |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CHsBackupRestoreObserver::RunL() |
|
163 { |
|
164 if ( iStatus.Int() == KErrNone ) |
|
165 { |
|
166 TInt currentValue = KErrNone; |
|
167 iProperty.Get( currentValue ); |
|
168 |
|
169 HandleBackupStateL( currentValue ); |
|
170 } |
|
171 // Re-subscribe notifications. |
|
172 SubscribePSKey(); |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // CHsBackupRestoreObserver::RunError |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 TInt CHsBackupRestoreObserver::RunError( TInt /*aError*/) |
|
180 { |
|
181 // No need to do anything |
|
182 return KErrNone; |
|
183 } |
|
184 |
|
185 // End of File |
|