15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "cntgroupactionsview.h" |
18 #include "cntgroupactionsview.h" |
19 |
19 |
20 #include <QGraphicsLinearLayout> |
20 #include <hblistview.h> |
21 #include <qtcontacts.h> |
21 #include <hbmenu.h> |
22 #include <hbdocumentloader.h> |
22 #include <hbaction.h> |
23 #include <QGraphicsSceneResizeEvent> |
23 #include <hblistview.h> |
24 #include <hbscrollarea.h> |
24 #include <hblistviewitem.h> |
25 #include <hbgroupbox.h> |
25 #include <hbview.h> |
26 #include <thumbnailmanager_qt.h> |
|
27 #include "cntcontactcarddatacontainer.h" |
|
28 #include "cntcontactcarddetailitem.h" |
|
29 #include "cntcontactcardheadingitem.h" |
|
30 #include "cntcommands.h" |
|
31 #include <hbdialog.h> |
|
32 #include <hbaction.h> |
26 #include <hbaction.h> |
33 #include <hblabel.h> |
27 #include <hblabel.h> |
|
28 #include <hbicon.h> |
|
29 #include <hbgroupbox.h> |
|
30 #include <mobcntmodel.h> |
|
31 #include <hbframebackground.h> |
34 |
32 |
|
33 #include <QStandardItemModel> |
35 |
34 |
36 const char *CNT_GROUPACTIONVIEW_XML = ":/xml/contacts_cc.docml"; |
35 const char *CNT_GROUPACTIONSVIEW_XML = ":/xml/contacts_groupactions.docml"; |
37 |
36 |
38 /*! |
37 CntGroupActionsView::CntGroupActionsView() : |
39 Constructor, initialize member variables. |
38 mGroupContact(NULL), |
40 \a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0) |
39 mModel(NULL), |
41 */ |
40 mViewManager(NULL), |
42 CntGroupActionsView::CntGroupActionsView(CntViewManager *viewManager, QGraphicsItem *parent) : |
41 mListView(NULL) |
43 CntBaseView(viewManager, parent), |
|
44 mGroupContact(0), |
|
45 mScrollArea(0), |
|
46 mContainerWidget(0), |
|
47 mContainerLayout(0), |
|
48 mDataContainer(0), |
|
49 mHeadingItem(0), |
|
50 mBanner(0) |
|
51 { |
42 { |
52 bool ok = false; |
43 bool ok = false; |
53 ok = loadDocument(CNT_GROUPACTIONVIEW_XML); |
44 mDocumentLoader.load(CNT_GROUPACTIONSVIEW_XML, &ok); |
54 |
45 |
55 if (ok) |
46 if (ok) |
56 { |
47 { |
57 QGraphicsWidget *content = findWidget(QString("content")); |
48 mView = static_cast<HbView*>(mDocumentLoader.findWidget(QString("view"))); |
58 setWidget(content); |
49 } |
59 } |
50 else |
60 else |
51 { |
61 { |
52 qFatal("Unable to read :/xml/contacts_groupactions.docml"); |
62 qFatal("Unable to read :/xml/contacts_cc.docml"); |
53 } |
63 } |
54 |
64 |
55 //back button |
|
56 mSoftkey = new HbAction(Hb::BackNaviAction, mView); |
|
57 connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView())); |
|
58 |
|
59 // menu actions |
|
60 mEditGrpDetailAction = static_cast<HbAction*>(mDocumentLoader.findObject("cnt:editgroupdetail")); |
|
61 connect(mEditGrpDetailAction, SIGNAL(triggered()), this, SLOT(editGroup())); |
65 } |
62 } |
66 |
63 |
67 /*! |
64 /*! |
68 Destructor |
65 Destructor |
69 */ |
66 */ |
70 CntGroupActionsView::~CntGroupActionsView() |
67 CntGroupActionsView::~CntGroupActionsView() |
71 { |
68 { |
|
69 mView->deleteLater(); |
|
70 |
|
71 delete mEditGrpDetailAction; |
|
72 mEditGrpDetailAction = NULL; |
|
73 |
72 delete mGroupContact; |
74 delete mGroupContact; |
73 delete mDataContainer; |
75 mGroupContact = NULL; |
|
76 |
|
77 delete mModel; |
|
78 mModel = NULL; |
74 } |
79 } |
75 |
80 |
76 |
81 |
77 void CntGroupActionsView::editGroup() |
82 void CntGroupActionsView::editGroup() |
78 { |
83 { |
79 CntViewParameters viewParameters(CntViewParameters::groupEditorView); |
84 CntViewParameters viewParameters; |
80 viewParameters.setSelectedAction("EditGroupMembers"); |
85 viewParameters.insert(EViewId, groupEditorView); |
81 viewParameters.setSelectedContact(*mGroupContact); |
86 QVariant var; |
82 viewManager()->changeView(viewParameters); |
87 var.setValue(*mGroupContact); |
|
88 viewParameters.insert(ESelectedContact, var); |
|
89 mViewManager->changeView(viewParameters); |
|
90 |
83 } |
91 } |
84 |
92 |
85 /*! |
|
86 Launch contact editor |
|
87 */ |
|
88 void CntGroupActionsView::editContact() |
|
89 { |
|
90 commands()->editContact(*mGroupContact); |
|
91 } |
|
92 |
93 |
93 /*! |
94 /*! |
94 Activates a previous view |
95 Activates a previous view |
95 */ |
96 */ |
96 void CntGroupActionsView::aboutToCloseView() |
97 void CntGroupActionsView::showPreviousView() |
97 { |
98 { |
98 CntViewParameters args; |
99 CntViewParameters viewParameters; |
99 args.setSelectedContact(*mGroupContact); |
100 QVariant var; |
100 viewManager()->back( args ); |
101 var.setValue(*mGroupContact); |
|
102 viewParameters.insert(ESelectedContact, var); |
|
103 mViewManager->back(viewParameters); |
101 } |
104 } |
102 |
105 |
103 void CntGroupActionsView::resizeEvent(QGraphicsSceneResizeEvent *event) |
106 void CntGroupActionsView::deactivate() |
104 { |
|
105 if (mScrollArea) |
|
106 { |
|
107 mContainerWidget->resize(mScrollArea->size().width(), 0); |
|
108 } |
|
109 CntBaseView::resizeEvent(event); |
|
110 } |
|
111 |
|
112 void CntGroupActionsView::addActionsToToolBar() |
|
113 { |
107 { |
114 |
108 |
115 } |
109 } |
|
110 |
116 /* |
111 /* |
117 Activates a default view and setup name label texts |
112 Activates a default view and setup name label texts |
118 */ |
113 */ |
119 void CntGroupActionsView::activateView(const CntViewParameters &viewParameters) |
114 void CntGroupActionsView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs ) |
120 { |
115 { |
121 QContact contact = viewParameters.selectedContact(); |
116 if (mView->navigationAction() != mSoftkey) |
122 mGroupContact = new QContact(contact); |
117 mView->setNavigationAction(mSoftkey); |
123 |
118 |
124 // add heading widget to the content |
119 mGroupContact = new QContact(aArgs.value(ESelectedContact).value<QContact>()); |
125 QGraphicsWidget *c = findWidget(QString("content")); |
120 mViewManager = aMgr; |
126 QGraphicsLinearLayout* l = static_cast<QGraphicsLinearLayout*>(c->layout()); |
|
127 |
121 |
128 QContactName groupContactName = mGroupContact->detail( QContactName::DefinitionName ); |
122 QContactName groupContactName = mGroupContact->detail( QContactName::DefinitionName ); |
129 QString groupName(groupContactName.value( QContactName::FieldCustomLabel )); |
123 QString groupName(groupContactName.value( QContactName::FieldCustomLabel )); |
130 |
|
131 mBanner = new HbGroupBox(this); |
|
132 l->insertItem(0, mBanner); |
|
133 mBanner->setHeading(groupName); |
|
134 |
124 |
135 |
125 |
136 |
126 //group box |
137 // data |
127 HbGroupBox* groupBox = static_cast<HbGroupBox *>(mDocumentLoader.findWidget(QString("groupBox"))); |
138 mDataContainer = new CntContactCardDataContainer(mGroupContact); |
128 groupBox->setHeading(groupName); |
139 |
|
140 mScrollArea = static_cast<HbScrollArea*>(findWidget(QString("scrollArea"))); |
|
141 mScrollArea->setScrollDirections(Qt::Vertical); |
|
142 |
|
143 mContainerWidget = new QGraphicsWidget(mScrollArea); |
|
144 mContainerWidget->setPreferredWidth(mScrollArea->size().width()); |
|
145 mScrollArea->setContentWidget(mContainerWidget); |
|
146 |
|
147 mContainerLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
148 mContainerLayout->setContentsMargins(0, 0, 0, 0); |
|
149 mContainerLayout->setSpacing(0); |
|
150 mContainerWidget->setLayout(mContainerLayout); |
|
151 |
129 |
152 for (int index = 0; index < mDataContainer->rowCount(); index++) |
130 // create list & model |
153 { |
131 mListView = static_cast<HbListView*> (mDocumentLoader.findWidget("listView")); |
154 // communication methods |
132 mListView->setUniformItemSizes(true); |
155 if (mDataContainer->separatorIndex() == -1 || index < mDataContainer->separatorIndex()) |
133 |
156 { |
134 HbFrameBackground frame; |
157 CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget); |
135 frame.setFrameGraphicsName("qtg_fr_list_parent_normal"); |
158 |
136 frame.setFrameType(HbFrameDrawer::NinePieces); |
159 connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated())); |
137 mListView->itemPrototypes().first()->setDefaultFrame(frame); |
160 |
138 |
161 HbIcon icon(""); |
139 mListView->listItemPrototype()->setGraphicsSize(HbListViewItem::LargeIcon); |
162 QString text; |
140 |
163 QString valueText; |
141 |
164 |
142 mModel = new QStandardItemModel(); |
165 // DecorationRole |
143 |
166 QVariant decorationRole = mDataContainer->data(index, Qt::DecorationRole); |
144 QContactPhoneNumber confCallNumber = mGroupContact->detail<QContactPhoneNumber>(); |
167 QVariantList variantList; |
145 if(!confCallNumber.number().isEmpty()) |
168 if (decorationRole.isValid()) |
146 { |
169 { |
147 populatelist(hbTrId("txt_phob_dblist_conference_call"), HbIcon("qtg_large_call_group"),confCallNumber.number()); |
170 if (decorationRole.canConvert<HbIcon>()) |
148 } |
171 { |
149 |
172 icon = decorationRole.value<HbIcon>(); |
150 populatelist(hbTrId("txt_phob_dblist_send_message"),HbIcon("qtg_large_message_group"),hbTrId("txt_phob_dblist_send_message_val_members")); |
173 } |
151 populatelist(hbTrId("txt_phob_dblist_email"),HbIcon("qtg_large_email_group"),hbTrId("txt_phob_dblist_send_message_val_members")); |
174 else if (decorationRole.canConvert< QList<QVariant> >()) |
152 |
175 { |
153 mListView->setModel(mModel); |
176 variantList = decorationRole.toList(); |
154 mListView->setSelectionMode(HbAbstractItemView::NoSelection); |
177 for (int j = 0; j < variantList.count(); j++) |
155 |
178 { |
|
179 if (j==0 && variantList.at(0).canConvert<HbIcon>()) |
|
180 { |
|
181 icon = variantList.at(0).value<HbIcon>(); |
|
182 } |
|
183 } |
|
184 } |
|
185 } |
|
186 |
|
187 // DisplayRole |
|
188 QVariant displayRole = mDataContainer->data(index, Qt::DisplayRole); |
|
189 QStringList stringList; |
|
190 if (displayRole.isValid()) |
|
191 { |
|
192 if (displayRole.canConvert<QString>()) |
|
193 { |
|
194 stringList.append(displayRole.toString()); |
|
195 } |
|
196 else if (displayRole.canConvert<QStringList>()) |
|
197 { |
|
198 stringList = displayRole.toStringList(); |
|
199 } |
|
200 } |
|
201 |
|
202 for (int j = 0; j < stringList.count(); j++) |
|
203 { |
|
204 if (j==0) |
|
205 { |
|
206 text = stringList.at(0); |
|
207 } |
|
208 else if (j==1) |
|
209 { |
|
210 valueText = stringList.at(1); |
|
211 } |
|
212 } |
|
213 QString confCall("Conference Call"); |
|
214 if(text==confCall) // conference call |
|
215 { |
|
216 item->setDetails(icon, text, valueText); |
|
217 } |
|
218 else |
|
219 { |
|
220 item->setDetails(icon, text); // for group Email and Message, we dont need any Value text |
|
221 } |
|
222 mContainerLayout->addItem(item); |
|
223 } |
|
224 } |
|
225 |
|
226 |
|
227 } |
156 } |
228 |
157 |
229 /*! |
158 void CntGroupActionsView:: populatelist(QString primaryText,HbIcon icon,QString secondaryText) |
230 Add actions to menu |
|
231 */ |
|
232 void CntGroupActionsView::addMenuItems() |
|
233 { |
159 { |
234 actions()->clearActionList(); |
160 QList<QStandardItem*> items; |
235 actions()->actionList() << actions()->baseAction("cnt:editgroupdetails"); |
161 QStandardItem *labelItem = new QStandardItem(); |
236 actions()->addActionsToMenu(menu()); |
162 |
237 |
163 QStringList textList; |
238 connect(actions()->baseAction("cnt:editgroupdetails"), SIGNAL(triggered()), |
164 |
239 this, SLOT (editGroup())); |
165 textList << primaryText << secondaryText; |
|
166 |
|
167 labelItem->setData(textList, Qt::DisplayRole); |
|
168 labelItem->setData(icon, Qt::DecorationRole); |
|
169 |
|
170 items << labelItem ; |
|
171 mModel->appendRow(items); |
240 } |
172 } |
241 |
|
242 |
|
243 |
|