summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/inc/cntphbksyncwatcher.h
blob: d75fe1f68ddbe1a5f787aa3be5dd6b41f51bcb7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/




/**
 @file
 @internalComponent
 @released
*/


#ifndef __CNTPHBKSYNCWATCHER_H__
#define __CNTPHBKSYNCWATCHER_H__


#include <cntsync.h>


class CSinglePhbkWatcher;


/**
Types of ICC Phonebook synchronisation tht Contact Views care about events.
*/
enum TPhonebookState 
	{
	/**
	Initial state, or ICC card has 'gone away' (e.g. ICC is resetting).
	*/
	EIccPhbkNotSynchronised,
	/**
	ICC Phonebook has completed synchronisation.
	*/
	EIccPhbkSynchronised,
	/**
	Sync failed due to ICC either being locked or not ready.
	*/
	EIccWaitForPhbkToBeReady,
	/**
	ICC Sync with Phonebook Server failed.
	*/
	EIccPhbkSyncError,
	};
	

/**	
An observer class for Contacts Views to track the status of ICC Phonebook
Synchronisation.
*/
class MContactPhbkSyncObserver
	{
public:
	virtual void ContactPhbkSyncEventHandler(TPhonebookState aPhbkState) = 0;
	};


/**
A watcher class for Contacts Views to track the status of ICC Phonebook
Synchronisation.
	
If created with a NULL pointer to the Phonebook Sync plugin implements default
behaviour of notifications (e.g. no Phonebook Synchroniser plugin present or
non-default database).
*/
NONSHARABLE_CLASS(CContactPhbkSyncWatcher) : public CBase
	{
public:
	static CContactPhbkSyncWatcher* NewL(MContactSynchroniser& aSyncPlugin);
	~CContactPhbkSyncWatcher();

	/**
	Add the object that sorts a contact view to the PhbkSync observer list.
	*/
	void AddPhbkObserverL(MContactPhbkSyncObserver& aPhbkObserver);

	/**
	Add the object that sorts a contact view to the PhbkSync observer list.
	*/
	void RemovePhbkObserver(MContactPhbkSyncObserver& aPhbkObserver);

	TInt PhonebooksReady();
	TInt PhonebooksWaiting();
	TInt PhonebookSyncError();
	
	TInt ObserverCount();

private:
	CContactPhbkSyncWatcher(MContactSynchroniser& aSyncPlugin);
	void ConstructL();

	friend class CSinglePhbkWatcher;
	MContactSynchroniser& SyncPlugin();
	void SendWatcherEvent(TPhonebookState aNewState, TPhonebookState aOldState, TInt aError=KErrNone);

private:
	MContactSynchroniser&				iSyncPlugin;
	RArray<MContactPhbkSyncObserver*>	iObservers;
	RPointerArray<CSinglePhbkWatcher>	iWatchers;
	TInt								iPhonebooksReady;
	TInt								iPhonebooksWaiting;
	TInt								iPhonebookErrors;
	TInt								iSyncError;
	};
	

NONSHARABLE_CLASS(CSinglePhbkWatcher) : public CActive
	{
public:
	static CSinglePhbkWatcher* NewLC(CContactPhbkSyncWatcher& aSyncWatcher, TUid& aPhonebookUid);
	~CSinglePhbkWatcher();
	TBool IsAcceptableError(TInt aSyncError);

private:
	CSinglePhbkWatcher(CContactPhbkSyncWatcher& aSyncWatcher, TUid& aPhonebookUid);

	void ConstructL();
	void Start();

	// From CActive.
	void DoCancel();
	void RunL();
	TInt RunError(TInt aError);

private:
	CContactPhbkSyncWatcher& 	iSyncWatcher;
	TUid						iPhonebookUid;
	TPhonebookState				iPhbkState;
	};


#endif // __CNTPHBKSYNCWATCHER_H__