~zeller-benjamin/address-book-app/sdkcompat

« back to all changes in this revision

Viewing changes to src/imports/Ubuntu/Contacts/ContactListView.qml

  • Committer: CI bot
  • Author(s): Renato Araujo Oliveira Filho
  • Date: 2014-08-28 21:27:04 UTC
  • mfrom: (277.2.10 release-2014-08-26)
  • Revision ID: ps-jenkins@lists.canonical.com-20140828212704-i5f91dqbuqrtqoiy
[Contacts] Split ContactListView in two components (ContactListView and ContactListModel).
[Contacts] Fixed most called list margin.
[ContactEditor] Changed from add field dialog to use ComboButtonAddField (requested by designers).
[I18n] Fixed desktop i18n rules. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
    /*
 
1
/*
2
2
 * Copyright (C) 2012-2013 Canonical, Ltd.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
52
52
      This property holds a string that will be used to filter contacts on the list
53
53
      By default this is set to empty
54
54
    */
55
 
    property string filterTerm: ""
 
55
    property alias filterTerm: contactsModel.filterTerm
56
56
    /*!
57
57
      \qmlproperty Filter filter
58
58
 
60
60
 
61
61
      \sa Filter
62
62
    */
63
 
    property var filter: null
 
63
    property alias filter: contactsModel.externalFilter
64
64
    /*!
65
65
      \qmlproperty bool showAvatar
66
66
 
285
285
    }
286
286
    function changeFilter(newFilter)
287
287
    {
288
 
        if (root.count > 0) {
289
 
            contactsModel._clearModel = true
290
 
        }
291
 
        root.filter = newFilter
 
288
        contactsModel.changeFilter(newFilter)
292
289
    }
293
290
    function reset()
294
291
    {
324
321
        contactsModel.update()
325
322
    }
326
323
 
327
 
    onFilterTermChanged: contactSearchTimeout.restart()
328
 
 
329
324
    // colapse contacts if the keyboard appears
330
325
    Connections {
331
326
        target: Qt.inputMethod
334
329
                view.currentIndex = -1
335
330
            }
336
331
        }
337
 
 
338
332
    }
339
333
 
340
334
    ContactSimpleListView {
341
335
        id: view
342
336
 
343
337
        property bool showFavourites: true
344
 
        property bool favouritesIsSelected: false
 
338
        property alias favouritesIsSelected: contactsModel.onlyFavorites
345
339
 
346
340
        function getSectionText(index) {
347
341
            var tag = listModel.contacts[index].tag.tag
377
371
        }
378
372
 
379
373
        header: Column {
380
 
            id: mostCalledView
381
 
 
382
374
            anchors {
383
375
                left: parent.left
384
376
                right: parent.right
385
377
            }
386
 
            onHeightChanged: {
387
 
                if (calledModel.currentIndex != -1) {
388
 
                    mostCalledView.makeItemVisible(callerRepeat.itemAt(calledModel.currentIndex))
389
 
                }
390
 
            }
 
378
            height: childrenRect.height
 
379
 
391
380
            Item {
392
 
                id: headerContents
 
381
                id: listHeader
 
382
 
393
383
                anchors {
394
384
                    left: parent.left
395
385
                    right: parent.right
 
386
                    margins: units.gu(1)
396
387
                }
397
388
                height: childrenRect.height
398
389
                children: root.header
399
390
            }
400
 
 
401
 
            Column {
402
 
                function makeItemVisible(item)
403
 
                {
404
 
                     var itemY = mostCalledView.y + item.y
405
 
                     var areaY = view.contentY
406
 
                     if (itemY < areaY) {
407
 
                         view.contentY = itemY
408
 
                         view.returnToBounds()
409
 
                     }
410
 
                }
411
 
 
412
 
                visible: view.favouritesIsSelected && (callerRepeat.count > 0)
 
391
            MostCalledList {
 
392
                id: mostCalledView
 
393
 
413
394
                anchors {
414
395
                    left: parent.left
415
396
                    right: parent.right
416
397
                }
417
 
                height: visible ? childrenRect.height : 0
418
 
 
419
 
                Rectangle {
420
 
                    color: Theme.palette.normal.background
421
 
                    anchors {
422
 
                        left: parent.left
423
 
                        right: parent.right
424
 
                        margins: units.gu(1)
425
 
                    }
426
 
                    height: units.gu(3)
427
 
                    Label {
428
 
                        anchors.fill: parent
429
 
                        verticalAlignment: Text.AlignVCenter
430
 
                        text: i18n.dtr("address-book-app", "Frequently called")
431
 
                        font.pointSize: 76
432
 
                    }
433
 
                    ListItem.ThinDivider {
434
 
                        anchors {
435
 
                            left: parent.left
436
 
                            right: parent.right
437
 
                            bottom: parent.bottom
438
 
                        }
439
 
                    }
440
 
                }
441
 
                Repeater {
442
 
                    id: callerRepeat
443
 
 
444
 
                    model: MostCalledModel {
445
 
                        id: calledModel
446
 
 
447
 
                        readonly property bool visible: view.favouritesIsSelected
448
 
 
449
 
                        onVisibleChanged: {
450
 
                            // update the model every time that it became visible
451
 
                            // in fact calling update only reloads the model data if it has changed
452
 
                            if (visible) {
453
 
                                model.update()
454
 
                            }
455
 
                        }
456
 
                        onInfoRequested: root.infoRequested(contact)
457
 
                        onDetailClicked: root.detailClicked(contact, detail, action)
458
 
                        onAddDetailClicked: root.addDetailClicked(contact, detailType)
459
 
                        onAddContactClicked: root.addContactClicked(label)
460
 
                        onCurrentIndexChanged:  {
461
 
                            if (currentIndex !== -1) {
462
 
                                view.currentIndex = -1
463
 
                            }
464
 
                        }
465
 
 
466
 
                        // WORKAROUND: The SDK header causes the contactY to move to a wrong postion
467
 
                        // calling the positionViewAtBeginning after the list created fix that
468
 
                        onLoaded: moveToBegining.restart()
469
 
                    }
470
 
                }
471
 
 
472
 
                Connections {
473
 
                    target: view
474
 
                    onCurrentIndexChanged: {
475
 
                        if (view.currentIndex !== -1) {
476
 
                            calledModel.currentIndex = -1
477
 
                        }
478
 
                    }
479
 
                }
 
398
                parentView: view
 
399
                visible: view.favouritesIsSelected
 
400
                height: visible && (count > 0) ? childrenRect.height : 0
480
401
            }
481
402
        }
482
403
        onError: root.error(message)
488
409
        onContactDisappeared: root.contactDisappeared(contact)
489
410
        clip: true
490
411
 
491
 
        InvalidFilter {
492
 
            id: invalidFilter
493
 
        }
494
 
 
495
 
        DetailFilter {
496
 
            id: favouritesFilter
497
 
 
498
 
            detail: ContactDetail.Favorite
499
 
            field: Favorite.Favorite
500
 
            value: true
501
 
            matchFlags: DetailFilter.MatchExactly
502
 
        }
503
 
 
504
 
        UnionFilter {
505
 
            id: contactTermFilter
506
 
 
507
 
            property string value: ""
508
 
 
509
 
            DetailFilter {
510
 
                detail: ContactDetail.DisplayLabel
511
 
                field: DisplayLabel.Label
512
 
                value: contactTermFilter.value
513
 
                matchFlags: DetailFilter.MatchContains
514
 
            }
515
 
 
516
 
            DetailFilter {
517
 
                detail: ContactDetail.PhoneNumber
518
 
                field: PhoneNumber.Number
519
 
                value: contactTermFilter.value
520
 
                matchFlags: DetailFilter.MatchPhoneNumber
521
 
            }
522
 
 
523
 
            DetailFilter {
524
 
                detail: ContactDetail.PhoneNumber
525
 
                field: PhoneNumber.Number
526
 
                value: contactTermFilter.value
527
 
                matchFlags: DetailFilter.MatchContains
528
 
            }
529
 
        }
530
 
 
531
 
 
532
 
        IntersectionFilter {
533
 
            id: contactsFilter
534
 
 
535
 
            // avoid runtime warning "depends on non-NOTIFYable properties"
536
 
            readonly property alias filtersProxy: contactsFilter.filters
537
 
 
538
 
            property bool active: {
539
 
                var filters_ = []
540
 
                if (contactTermFilter.value.length > 0) {
541
 
                    filters_.push(contactTermFilter)
542
 
                } else if (view.favouritesIsSelected) {
543
 
                    filters_.push(favouritesFilter)
544
 
                }
545
 
 
546
 
                if (root.filter) {
547
 
                    filters_.push(root.filter)
548
 
                }
549
 
 
550
 
                // check if the filter has changed
551
 
                var oldFilters = filtersProxy
552
 
                if (oldFilters.length !== filters_.length) {
553
 
                    contactsFilter.filters = filters_
554
 
                } else {
555
 
                    for(var i=0; i < oldFilters.length; i++) {
556
 
                        if (filters_.indexOf(oldFilters[i]) === -1) {
557
 
                            contactsFilter.filters = filters_
558
 
                        }
559
 
                    }
560
 
                }
561
 
 
562
 
                return (filters_.length > 0)
563
 
            }
564
 
        }
565
 
 
566
 
        Timer {
567
 
            id: contactSearchTimeout
568
 
 
569
 
            running: false
570
 
            repeat: false
571
 
            interval: 300
572
 
            onTriggered: {
573
 
                view.positionViewAtBeginning()
574
 
 
575
 
                root.changeFilter(root.filter)
576
 
                contactTermFilter.value = root.filterTerm
577
 
 
578
 
                // manually update if autoUpdate is disabled
579
 
                if (!root.autoUpdate) {
580
 
                    contactsModel.update()
581
 
                }
582
 
            }
583
 
        }
584
 
 
585
 
        listModel: ContactModel {
 
412
        listModel: ContactListModel {
586
413
            id: contactsModel
587
414
 
588
 
            property bool _clearModel: false
589
 
 
590
415
            manager: root.manager
591
416
            sortOrders: root.sortOrders
592
417
            fetchHint: root.fetchHint
593
 
            filter: {
594
 
                if (contactsModel._clearModel) {
595
 
                    return invalidFilter
596
 
                } else if (contactsFilter.active) {
597
 
                    return contactsFilter
598
 
                } else {
599
 
                    return null
600
 
                }
601
 
            }
602
 
 
603
 
            onErrorChanged: {
604
 
                if (error) {
605
 
                    console.error("Contact List error:" + error)
606
 
                }
607
 
            }
608
 
 
609
 
            onContactsChanged: {
610
 
                //WORKAROUND: clear the model before start populate it with the new contacts
611
 
                //otherwise the model will wait for all contacts before show any new contact
612
 
 
613
 
                //after all contacts get removed we can populate the model again, this will show
614
 
                //new contacts as soon as it arrives in the model
615
 
                if (contactsModel._clearModel && contacts.length === 0) {
616
 
                    contactsModel._clearModel = false
617
 
                    // do a new update if autoUpdate is false
618
 
                    if (!contactsModel.autoUpdate) {
619
 
                        contactsModel.update()
620
 
                    }
621
 
 
622
 
                }
623
 
            }
624
418
        }
625
419
    }
626
420