63
|
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 |
* Provides methods for phonebook add item manager.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
|
|
22 |
// This class
|
|
23 |
#include "TPbkAddItemManager.h"
|
|
24 |
|
|
25 |
// PbkView classes
|
|
26 |
#include "TPbkAddItemWrapper.h"
|
|
27 |
#include "CPbkMemoryEntrySelectAddItemDlg.h"
|
|
28 |
#include "MPbkContactEditorCreateField.h"
|
|
29 |
#include <MPbkContactEditorField.h>
|
|
30 |
|
|
31 |
// PbkEng classes
|
|
32 |
#include <CPbkFieldsInfo.h>
|
|
33 |
#include <CPbkFieldInfo.h>
|
|
34 |
#include <CPbkFieldInfoGroup.h>
|
|
35 |
#include <CPbkContactItem.h>
|
|
36 |
|
|
37 |
// ==================== MEMBER FUNCTIONS ====================
|
|
38 |
TPbkAddItemManager::TPbkAddItemManager
|
|
39 |
(CPbkContactItem& aItem,
|
|
40 |
MPbkContactEditorCreateField& aAddField) :
|
|
41 |
iContactItem(aItem),
|
|
42 |
iAddField(aAddField)
|
|
43 |
{
|
|
44 |
}
|
|
45 |
|
|
46 |
TPbkAddItemManager::~TPbkAddItemManager()
|
|
47 |
{
|
|
48 |
}
|
|
49 |
|
|
50 |
void TPbkAddItemManager::AddFieldsL(
|
|
51 |
const CPbkFieldsInfo& aFieldsInfo,
|
|
52 |
RArray<TInt>& aAddedItemsControlIds)
|
|
53 |
{
|
|
54 |
RArray<TPbkAddItemWrapper> addItems(4);
|
|
55 |
CleanupClosePushL(addItems);
|
|
56 |
|
|
57 |
// Create array of TPbkAddItemWrapper items to show in the
|
|
58 |
// select dialog
|
|
59 |
CreateAddItemArrayL(aFieldsInfo, addItems);
|
|
60 |
|
|
61 |
// Create and show dialog for selecting fieldinfo(s) to add to contact
|
|
62 |
CPbkMemoryEntrySelectAddItemDlg* addDlg =
|
|
63 |
new (ELeave) CPbkMemoryEntrySelectAddItemDlg;
|
|
64 |
TPbkAddItemWrapper* addWrapper = addDlg->ExecuteLD(addItems);
|
|
65 |
|
|
66 |
if (addWrapper)
|
|
67 |
{
|
|
68 |
AddFieldsToContactL(*addWrapper, aAddedItemsControlIds);
|
|
69 |
}
|
|
70 |
|
|
71 |
CleanupStack::PopAndDestroy(); // addItems
|
|
72 |
}
|
|
73 |
|
|
74 |
TBool TPbkAddItemManager::ContactHasGroupItems(
|
|
75 |
const CPbkFieldInfoGroup& aGroup) const
|
|
76 |
{
|
|
77 |
for (TInt i = 0; i < aGroup.Count(); ++i)
|
|
78 |
{
|
|
79 |
if (iContactItem.FindField(aGroup.At(i)))
|
|
80 |
{
|
|
81 |
// Field defined in group found from contact
|
|
82 |
return ETrue;
|
|
83 |
}
|
|
84 |
}
|
|
85 |
// None of the fields of the group was found from the contact
|
|
86 |
return EFalse;
|
|
87 |
}
|
|
88 |
|
|
89 |
void TPbkAddItemManager::AddFieldsToContactL(
|
|
90 |
const TPbkAddItemWrapper& aItemWrapper,
|
|
91 |
RArray<TInt>& aAddedItemsControlIds)
|
|
92 |
{
|
|
93 |
CleanupClosePushL( aAddedItemsControlIds );
|
|
94 |
aAddedItemsControlIds.Reset();
|
|
95 |
|
|
96 |
for (TInt i = 0; i < aItemWrapper.FieldInfoCount(); ++i)
|
|
97 |
{
|
|
98 |
CPbkFieldInfo* fieldInfo = aItemWrapper.FieldInfoAt(i);
|
|
99 |
if (fieldInfo)
|
|
100 |
{
|
|
101 |
// add field to contact and list of added fields
|
|
102 |
MPbkContactEditorField& field = iAddField.CreateFieldL(*fieldInfo);
|
|
103 |
User::LeaveIfError(aAddedItemsControlIds.Append(field.ControlId()));
|
|
104 |
}
|
|
105 |
}
|
|
106 |
CleanupStack::Pop();
|
|
107 |
}
|
|
108 |
|
|
109 |
/**
|
|
110 |
* This function creates the list of selectable items for the
|
|
111 |
* query dialog in aAddItems array. The items are either CPbkFieldInfo
|
|
112 |
* or CPbkFieldInfoGroup instances wrapped in TPbkAddItemWrapper.
|
|
113 |
*/
|
|
114 |
void TPbkAddItemManager::CreateAddItemArrayL(
|
|
115 |
const CPbkFieldsInfo& aFieldsInfo,
|
|
116 |
RArray<TPbkAddItemWrapper>& aAddItems) const
|
|
117 |
{
|
|
118 |
CleanupClosePushL( aAddItems );
|
|
119 |
aAddItems.Reset();
|
|
120 |
const TInt fieldInfoCount = aFieldsInfo.Count();
|
|
121 |
|
|
122 |
RPointerArray<CPbkFieldInfoGroup> addedGroups;
|
|
123 |
CleanupClosePushL(addedGroups);
|
|
124 |
|
|
125 |
for (TInt i=0; i < fieldInfoCount; ++i)
|
|
126 |
{
|
|
127 |
CPbkFieldInfo* fieldInfo = aFieldsInfo[i];
|
|
128 |
if ( fieldInfo->UserCanAddField() &&
|
|
129 |
( fieldInfo->Multiplicity() == EPbkFieldMultiplicityMany ||
|
|
130 |
!iContactItem.FindField(*fieldInfo)) )
|
|
131 |
{
|
|
132 |
const CPbkFieldInfoGroup* group = fieldInfo->Group();
|
|
133 |
if (group)
|
|
134 |
{
|
|
135 |
// If item has group definition we must decide whether to
|
|
136 |
// add the field info, field info group or nothing.
|
|
137 |
if (addedGroups.Find(group) == KErrNotFound)
|
|
138 |
{
|
|
139 |
// Add the group or item only if the group in question
|
|
140 |
// is not already added.
|
|
141 |
if (ContactHasGroupItems(*group))
|
|
142 |
{
|
|
143 |
// Contact already has at least one item of the group;
|
|
144 |
// add only current field.
|
|
145 |
User::LeaveIfError(aAddItems.Append(
|
|
146 |
TPbkAddItemWrapper(*fieldInfo)));
|
|
147 |
}
|
|
148 |
else
|
|
149 |
{
|
|
150 |
// No items of the group exist in contact: add the whole
|
|
151 |
// group and not only the field in question.
|
|
152 |
User::LeaveIfError(aAddItems.Append(
|
|
153 |
TPbkAddItemWrapper(*group)));
|
|
154 |
// Add group to "added groups" list
|
|
155 |
User::LeaveIfError(addedGroups.Append(group));
|
|
156 |
}
|
|
157 |
}
|
|
158 |
}
|
|
159 |
else
|
|
160 |
{
|
|
161 |
// No group defined for the field; add only the current field.
|
|
162 |
User::LeaveIfError(aAddItems.Append(TPbkAddItemWrapper(*fieldInfo)));
|
|
163 |
}
|
|
164 |
}
|
|
165 |
}
|
|
166 |
CleanupStack::PopAndDestroy(); // addedGroups
|
|
167 |
CleanupStack::Pop();
|
|
168 |
}
|
|
169 |
|
|
170 |
// End of File
|