72
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "cntmycardview.h"
|
|
19 |
#include "cntfetchcontactpopup.h"
|
|
20 |
#include "cntglobal.h"
|
|
21 |
|
|
22 |
#include <qtcontacts.h>
|
|
23 |
#include <hbpushbutton.h>
|
|
24 |
#include <hbaction.h>
|
|
25 |
#include <hbview.h>
|
|
26 |
#include <hbmainwindow.h>
|
|
27 |
|
|
28 |
const char *CNT_MYCARD_UI_XML = ":/xml/contacts_mc.docml";
|
|
29 |
|
|
30 |
CntMyCardView::CntMyCardView() :
|
|
31 |
mContact(NULL),
|
|
32 |
mViewManager(NULL)
|
|
33 |
{
|
|
34 |
bool ok = false;
|
|
35 |
mDocumentLoader.load(CNT_MYCARD_UI_XML, &ok);
|
|
36 |
|
|
37 |
if (ok)
|
|
38 |
{
|
|
39 |
mView = static_cast<HbView*>(mDocumentLoader.findWidget(QString("view")));
|
|
40 |
}
|
|
41 |
else
|
|
42 |
{
|
|
43 |
qFatal("Unable to read :/xml/contacts_mc.docml");
|
|
44 |
}
|
|
45 |
|
|
46 |
//back button
|
|
47 |
mSoftkey = new HbAction(Hb::BackNaviAction, mView);
|
|
48 |
connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
|
|
49 |
}
|
|
50 |
|
|
51 |
CntMyCardView::~CntMyCardView()
|
|
52 |
{
|
|
53 |
mView->deleteLater();
|
|
54 |
|
|
55 |
delete mContact;
|
|
56 |
mContact = NULL;
|
|
57 |
}
|
|
58 |
|
|
59 |
/*!
|
|
60 |
Activates a previous view
|
|
61 |
*/
|
|
62 |
void CntMyCardView::showPreviousView()
|
|
63 |
{
|
|
64 |
CntViewParameters args;
|
|
65 |
mViewManager->back(args);
|
|
66 |
}
|
|
67 |
|
|
68 |
/*
|
|
69 |
Activates a default view
|
|
70 |
*/
|
|
71 |
void CntMyCardView::activate(const CntViewParameters aArgs)
|
|
72 |
{
|
|
73 |
mViewManager = &mEngine->viewManager();
|
|
74 |
|
|
75 |
if (mView->navigationAction() != mSoftkey) {
|
|
76 |
mView->setNavigationAction(mSoftkey);
|
|
77 |
}
|
|
78 |
|
|
79 |
HbMainWindow* window = mView->mainWindow();
|
|
80 |
connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
|
|
81 |
setOrientation(window->orientation());
|
|
82 |
|
|
83 |
mContact = new QContact(aArgs.value(ESelectedContact).value<QContact>());
|
|
84 |
HbPushButton *newButton = static_cast<HbPushButton*>(mDocumentLoader.findWidget(QString("cnt_button_new")));
|
|
85 |
connect(newButton, SIGNAL(clicked()), this, SLOT(openNameEditor()));
|
|
86 |
connect(newButton, SIGNAL(longPress(QPointF)), this, SLOT(openNameEditor()));
|
|
87 |
|
|
88 |
HbPushButton *chooseButton = static_cast<HbPushButton*>(mDocumentLoader.findWidget(QString("cnt_button_choose")));
|
|
89 |
connect(chooseButton, SIGNAL(clicked()), this, SLOT(openMyCardSelectionView()));
|
|
90 |
connect(chooseButton, SIGNAL(longPress(QPointF)), this, SLOT(openMyCardSelectionView()));
|
|
91 |
|
|
92 |
QContactDetailFilter filter;
|
|
93 |
filter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
|
|
94 |
filter.setValue(QLatin1String(QContactType::TypeContact));
|
|
95 |
|
|
96 |
if (mEngine->contactManager( SYMBIAN_BACKEND ).contactIds(filter).isEmpty())
|
|
97 |
{
|
|
98 |
chooseButton->setEnabled(false);
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
void CntMyCardView::deactivate()
|
|
103 |
{
|
|
104 |
}
|
|
105 |
|
|
106 |
void CntMyCardView::setOrientation(Qt::Orientation orientation)
|
|
107 |
{
|
|
108 |
if (orientation == Qt::Vertical)
|
|
109 |
{
|
|
110 |
// reading "portrait" section
|
|
111 |
mDocumentLoader.load(CNT_MYCARD_UI_XML, "portrait");
|
|
112 |
}
|
|
113 |
else
|
|
114 |
{
|
|
115 |
// reading "landscape" section
|
|
116 |
mDocumentLoader.load(CNT_MYCARD_UI_XML, "landscape");
|
|
117 |
}
|
|
118 |
}
|
|
119 |
|
|
120 |
/*!
|
|
121 |
Opens the name detail editor view
|
|
122 |
*/
|
|
123 |
void CntMyCardView::openNameEditor()
|
|
124 |
{
|
|
125 |
CntViewParameters viewParameters;
|
|
126 |
viewParameters.insert(EViewId, editView);
|
|
127 |
viewParameters.insert(EMyCard, "myCard" );
|
|
128 |
|
|
129 |
QVariant var;
|
|
130 |
var.setValue(*mContact);
|
|
131 |
viewParameters.insert(ESelectedContact, var);
|
|
132 |
viewParameters.insert(EExtraAction, CNT_ROOT_ACTION);
|
|
133 |
mViewManager->changeView(viewParameters);
|
|
134 |
}
|
|
135 |
|
|
136 |
/*!
|
|
137 |
Opens the my card selection view
|
|
138 |
*/
|
|
139 |
void CntMyCardView::openMyCardSelectionView()
|
|
140 |
{
|
|
141 |
CntFetchContactPopup* popup = CntFetchContactPopup::createSingleSelectionPopup(
|
|
142 |
hbTrId("txt_phob_title_select_contact"),
|
|
143 |
mEngine->contactManager(SYMBIAN_BACKEND));
|
|
144 |
connect( popup, SIGNAL(fetchReady(QSet<QContactLocalId>)), this, SLOT(handleMultiCardSelection(QSet<QContactLocalId>)));
|
|
145 |
QSet<QContactLocalId> ids;
|
|
146 |
popup->setSelectedContacts(ids);
|
|
147 |
popup->showPopup();
|
|
148 |
}
|
|
149 |
|
|
150 |
void CntMyCardView::handleMultiCardSelection( QSet<QContactLocalId> aIds )
|
|
151 |
{
|
|
152 |
QContactManager& manager = mEngine->contactManager( SYMBIAN_BACKEND );
|
|
153 |
|
|
154 |
if ( !aIds.isEmpty() ) {
|
|
155 |
QList<QContactLocalId> selectedContactsList = aIds.values();
|
|
156 |
QContact contact = manager.contact(selectedContactsList.front());
|
|
157 |
removeFromGroup(&contact);
|
|
158 |
|
|
159 |
manager.setSelfContactId( contact.localId() );
|
|
160 |
showPreviousView();
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
void CntMyCardView::removeFromGroup(const QContact* aContact)
|
|
165 |
{
|
|
166 |
// Fetch all groups the contact is member and remove the relationships
|
|
167 |
QContactManager& mgr = mEngine->contactManager(SYMBIAN_BACKEND);
|
|
168 |
QContactRelationshipFilter relationshipFilter;
|
|
169 |
relationshipFilter.setRelationshipType(QContactRelationship::HasMember);
|
|
170 |
relationshipFilter.setRelatedContactId(aContact->id());
|
|
171 |
relationshipFilter.setRelatedContactRole(QContactRelationship::Second);
|
|
172 |
QList<QContactLocalId> groupIds = mgr.contactIds(relationshipFilter);
|
|
173 |
|
|
174 |
QList<QContactRelationship> relationships;
|
|
175 |
for(int i = 0;i < groupIds.count();i++) {
|
|
176 |
QContact groupContact = mgr.contact(groupIds.at(i));
|
|
177 |
QContactRelationship relationship;
|
|
178 |
relationship.setRelationshipType(QContactRelationship::HasMember);
|
|
179 |
relationship.setFirst(groupContact.id());
|
|
180 |
relationship.setSecond(aContact->id());
|
|
181 |
relationships.append(relationship);
|
|
182 |
}
|
|
183 |
QMap<int, QContactManager::Error> errorMap;
|
|
184 |
mgr.removeRelationships(relationships,&errorMap);
|
|
185 |
}
|
|
186 |
|
|
187 |
// EOF
|