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 |
#include "cntnoteeditormodel.h"
|
|
18 |
#include "cntdetailmodelitem.h"
|
|
19 |
#include <qcontactnote.h>
|
|
20 |
|
|
21 |
CntNoteEditorModel::CntNoteEditorModel( QContact* aContact ) :
|
|
22 |
CntDetailEditorModel( aContact )
|
|
23 |
{
|
|
24 |
HbDataFormModelItem* root = invisibleRootItem();
|
|
25 |
foreach ( QContactNote note, mContact->details<QContactNote>() )
|
|
26 |
{
|
|
27 |
CntDetailModelItem* item = new CntDetailModelItem(note);
|
|
28 |
appendDataFormItem( item, root );
|
|
29 |
connect( item, SIGNAL(itemDataChanged(CntDetailModelItem*)), this, SLOT(emitDataChanged(CntDetailModelItem*)) );
|
|
30 |
}
|
|
31 |
}
|
|
32 |
|
|
33 |
CntNoteEditorModel::~CntNoteEditorModel()
|
|
34 |
{
|
|
35 |
}
|
|
36 |
|
|
37 |
void CntNoteEditorModel::insertDetailField()
|
|
38 |
{
|
|
39 |
QContactNote emptyNote;
|
|
40 |
mNoteList.append( emptyNote );
|
|
41 |
CntDetailModelItem* newNote = new CntDetailModelItem(emptyNote);
|
|
42 |
appendDataFormItem( newNote, invisibleRootItem() );
|
|
43 |
connect( newNote, SIGNAL(itemDataChanged(CntDetailModelItem*)), this, SLOT(emitDataChanged(CntDetailModelItem*)) );
|
|
44 |
emitDataChanged(newNote);
|
|
45 |
}
|
|
46 |
|
|
47 |
void CntNoteEditorModel::saveContactDetails()
|
|
48 |
{
|
|
49 |
HbDataFormModelItem* root = invisibleRootItem();
|
|
50 |
|
|
51 |
int count( root->childCount() );
|
|
52 |
for ( int i(0); i < count; i++ ) {
|
|
53 |
CntDetailModelItem* detail = static_cast<CntDetailModelItem*>( root->childAt(i) );
|
|
54 |
QContactNote note = detail->detail();
|
|
55 |
|
|
56 |
if ( !mNoteList.contains(note) )
|
|
57 |
{
|
|
58 |
mContact->saveDetail( ¬e );
|
|
59 |
}
|
|
60 |
|
|
61 |
if ( note.note().isEmpty() )
|
|
62 |
{
|
|
63 |
mContact->removeDetail( ¬e );
|
|
64 |
}
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
QContactDetail CntNoteEditorModel::detail() const
|
|
69 |
{
|
|
70 |
QListIterator<QContactNote> noteList(mContact->details<QContactNote>());
|
|
71 |
noteList.toBack(); // go through backwards, so the newest item will be returned
|
|
72 |
while ( noteList.hasPrevious() )
|
|
73 |
{
|
|
74 |
QContactNote note = noteList.previous();
|
|
75 |
if ( !note.value(QContactNote::FieldNote).isEmpty() )
|
|
76 |
{
|
|
77 |
return note;
|
|
78 |
}
|
|
79 |
}
|
|
80 |
return QContactNote(); // return empty address if none found
|
|
81 |
}
|
|
82 |
|
|
83 |
// End of File
|