22 #include "cnteditviewdetailitem.h" |
22 #include "cnteditviewdetailitem.h" |
23 #include "cnteditviewitembuilder.h" |
23 #include "cnteditviewitembuilder.h" |
24 #include <cntviewparams.h> |
24 #include <cntviewparams.h> |
25 #include <QDir> |
25 #include <QDir> |
26 |
26 |
27 CntEditViewListModel::CntEditViewListModel( QContact& aContact ) : |
27 CntEditViewListModel::CntEditViewListModel( QContact& aContact, CntExtensionManager& aMgr ) : |
28 mContact( aContact ) |
28 mContact( aContact ), |
|
29 mManager( aMgr ) |
29 { |
30 { |
30 mLookupTable.insert( EPhonenumber, -1 ); |
31 mLookupTable.insert( EPhonenumber, -1 ); |
31 mLookupTable.insert( EEmailAddress, -1 ); |
32 mLookupTable.insert( EEmailAddress, -1 ); |
32 mLookupTable.insert( EAddressTemplate,-1 ); |
33 mLookupTable.insert( EAddressTemplate,-1 ); |
33 mLookupTable.insert( EPluginItem, -1 ); |
34 mLookupTable.insert( EPluginItem, -1 ); |
51 mLookupMap.insert( QContactAnniversary::DefinitionName, EDate); |
52 mLookupMap.insert( QContactAnniversary::DefinitionName, EDate); |
52 mLookupMap.insert( QContactRingtone::DefinitionName, ERingingTone); |
53 mLookupMap.insert( QContactRingtone::DefinitionName, ERingingTone); |
53 mLookupMap.insert( QContactNote::DefinitionName, ENote); |
54 mLookupMap.insert( QContactNote::DefinitionName, ENote); |
54 mLookupMap.insert( QContactFamily::DefinitionName, EFamily); |
55 mLookupMap.insert( QContactFamily::DefinitionName, EFamily); |
55 |
56 |
56 mManager = new CntExtensionManager(); |
|
57 mBuilder = new CntEditViewItemBuilder(); |
57 mBuilder = new CntEditViewItemBuilder(); |
58 mSeparator = new CntEditViewSeparator(); |
58 mSeparator = new CntEditViewSeparator(); |
59 |
59 |
60 refresh(); |
60 refresh(); |
61 } |
61 } |
214 } |
212 } |
215 } |
213 } |
216 |
214 |
217 void CntEditViewListModel::refreshExtensionItems() |
215 void CntEditViewListModel::refreshExtensionItems() |
218 { |
216 { |
219 beginResetModel(); |
217 // remove and delete all extension items |
220 // remove all extension items |
|
221 for( int i(mItemList.count()-1); i >= 0; i-- ) |
218 for( int i(mItemList.count()-1); i >= 0; i-- ) |
222 { |
219 { |
223 CntEditViewItem* item = mItemList.at( i ); |
220 CntEditViewItem* item = mItemList.at( i ); |
224 if ( item->data(ERoleItemType) == QVariant(ETypeUiExtension) ) |
221 if ( item->data(ERoleItemType) == QVariant(ETypeUiExtension) ) |
225 { |
222 { |
|
223 QModelIndex modelIndex = createIndex(i, 0); |
|
224 beginRemoveRows( modelIndex.parent(), i, i ); |
226 mItemList.removeAt(i); |
225 mItemList.removeAt(i); |
227 removeItem( EPluginItem ); |
226 removeItem( EPluginItem ); |
228 } |
227 |
229 } |
228 delete item; |
230 // query extension items again |
229 endRemoveRows(); |
231 int count = mManager->pluginCount(); |
230 } |
|
231 } |
|
232 // query and reload extension items again |
|
233 int count = mManager.pluginCount(); |
232 for ( int i(0); i < count; i++ ) |
234 for ( int i(0); i < count; i++ ) |
233 { |
235 { |
234 CntUiExtensionFactory* factory = mManager->pluginAt(i); |
236 CntUiExtensionFactory* factory = mManager.pluginAt(i); |
235 CntEditViewItemSupplier* supplier = factory->editViewItemSupplier( mContact ); |
237 CntEditViewItemSupplier* supplier = factory->editViewItemSupplier( mContact ); |
236 if (supplier) |
238 if (supplier) |
237 { |
239 { |
238 loadPluginItems( supplier ); |
240 loadPluginItems( supplier ); |
239 } |
241 } |
240 } |
242 } |
241 endResetModel(); |
|
242 } |
243 } |
243 |
244 |
244 void CntEditViewListModel::allInUseFields( CntViewIdList& aList ) |
245 void CntEditViewListModel::allInUseFields( CntViewIdList& aList ) |
245 { |
246 { |
246 foreach ( KLookupKey key, mLookupTable.keys() ) |
247 foreach ( KLookupKey key, mLookupTable.keys() ) |
319 return itemIndex; |
320 return itemIndex; |
320 } |
321 } |
321 |
322 |
322 void CntEditViewListModel::refresh() |
323 void CntEditViewListModel::refresh() |
323 { |
324 { |
324 beginResetModel(); |
|
325 |
|
326 insertItem( EPhonenumber, mBuilder->phoneNumberItems(mContact) ); |
325 insertItem( EPhonenumber, mBuilder->phoneNumberItems(mContact) ); |
327 insertItem( EEmailAddress, mBuilder->emailAddressItems(mContact) ); |
326 insertItem( EEmailAddress, mBuilder->emailAddressItems(mContact) ); |
328 insertItem( EAddressTemplate, mBuilder->addressItems(mContact) ); |
327 insertItem( EAddressTemplate, mBuilder->addressItems(mContact) ); |
329 insertItem( EUrl, mBuilder->urlItems(mContact) ); |
328 insertItem( EUrl, mBuilder->urlItems(mContact) ); |
330 |
329 |
331 int count = mManager->pluginCount(); |
330 int count = mManager.pluginCount(); |
332 for ( int i(0); i < count; i++ ) |
331 for ( int i(0); i < count; i++ ) |
333 { |
332 { |
334 CntUiExtensionFactory* factory = mManager->pluginAt(i); |
333 CntUiExtensionFactory* factory = mManager.pluginAt(i); |
335 CntEditViewItemSupplier* supplier = factory->editViewItemSupplier( mContact ); |
334 CntEditViewItemSupplier* supplier = factory->editViewItemSupplier( mContact ); |
336 if (supplier) |
335 if (supplier) |
337 { |
336 { |
338 loadPluginItems( supplier ); |
337 loadPluginItems( supplier ); |
339 } |
338 } |
343 insertDetailItem( ECompany, mBuilder->companyDetails(mContact) ); |
342 insertDetailItem( ECompany, mBuilder->companyDetails(mContact) ); |
344 insertDetailItem( EDate, mBuilder->dateDetails(mContact) ); |
343 insertDetailItem( EDate, mBuilder->dateDetails(mContact) ); |
345 insertDetailItem( ENote, mBuilder->noteDetails(mContact) ); |
344 insertDetailItem( ENote, mBuilder->noteDetails(mContact) ); |
346 insertDetailItem( EFamily, mBuilder->familyDetails(mContact) ); |
345 insertDetailItem( EFamily, mBuilder->familyDetails(mContact) ); |
347 insertDetailItem( ERingingTone, mBuilder->ringtoneDetails(mContact) ); |
346 insertDetailItem( ERingingTone, mBuilder->ringtoneDetails(mContact) ); |
348 |
|
349 endResetModel(); |
|
350 } |
347 } |
351 |
348 |
352 bool CntEditViewListModel::isEmptyItem( CntEditViewItem* aItem ) |
349 bool CntEditViewListModel::isEmptyItem( CntEditViewItem* aItem ) |
353 { |
350 { |
354 if ( aItem ) |
351 if ( aItem ) |
379 list << item; |
376 list << item; |
380 } |
377 } |
381 } |
378 } |
382 |
379 |
383 if ( !list.isEmpty() ) |
380 if ( !list.isEmpty() ) |
|
381 { |
|
382 // the new items will be inserted under already existing plugin items... |
|
383 int index = mLookupTable.value( EPluginItem ); |
|
384 |
|
385 // ... or under the address template (if no plugins exist) |
|
386 if (index == -1) |
|
387 { |
|
388 index = mLookupTable.value( EAddressTemplate ); |
|
389 } |
|
390 |
|
391 // ... or as a final choice, under the email address items (if address template doesn't exist) |
|
392 if (index == -1) |
|
393 { |
|
394 index = mLookupTable.value( EEmailAddress ); |
|
395 } |
|
396 QModelIndex modelIndex = createIndex(index, 0); |
|
397 beginInsertRows(modelIndex.parent(), index + 1, index + count); |
384 insertItem( EPluginItem, list ); |
398 insertItem( EPluginItem, list ); |
|
399 endInsertRows(); |
|
400 } |
385 } |
401 } |
386 |
402 |
387 void CntEditViewListModel::insertDetailItem( KLookupKey aKey, QList<CntEditViewItem*> aList ) |
403 void CntEditViewListModel::insertDetailItem( KLookupKey aKey, QList<CntEditViewItem*> aList ) |
388 { |
404 { |
389 if ( !aList.isEmpty() ) |
405 if ( !aList.isEmpty() ) |