Warning, /maui/communicator/src/views/contacts/ContactsView.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.14
0002 import QtQuick.Controls 2.14
0003 import QtQuick.Layouts 1.3
0004 
0005 import QtGraphicalEffects 1.0
0006 
0007 import org.mauikit.controls 1.3 as Maui
0008 
0009 import org.maui.communicator 1.0
0010 
0011 Maui.AltBrowser
0012 {
0013     id: control
0014 
0015     property alias list : _contactsList
0016     property alias listModel : _contactsModel
0017 
0018     property bool showAccountFilter: false
0019 
0020     property var currentContact : ({})
0021 
0022     holder.visible: !currentView.count
0023     headBar.visible: true
0024     headBar.forceCenterMiddleContent: root.isWide
0025     //        onActionTriggered: _newContactDialog.open()
0026 
0027     model: Maui.BaseModel
0028     {
0029         id: _contactsModel
0030         list: ContactsList
0031         {
0032             id: _contactsList
0033         }
0034         sort: "n"
0035         sortOrder: Qt.AscendingOrder
0036         recursiveFilteringEnabled: true
0037         sortCaseSensitivity: Qt.CaseInsensitive
0038         filterCaseSensitivity: Qt.CaseInsensitive
0039     }
0040 
0041     //        headBar.leftContent: ToolButton
0042     //        {
0043     //            //            enabled: _contactsModel.count > 0
0044     //            icon.name: control.viewType === Maui.AltBrowser.ViewType.List ? "view-list-icons" : "view-list-details"
0045 
0046     //            onClicked:
0047     //            {
0048     //                control.viewType =  control.viewType === Maui.AltBrowser.ViewType.List ? Maui.AltBrowser.ViewType.Grid : Maui.AltBrowser.ViewType.List
0049     //            }
0050     //        }
0051 
0052     headBar.middleContent: Maui.SearchField
0053     {
0054         id: _searchField
0055         Layout.fillWidth: true
0056         Layout.maximumWidth: 500
0057         Layout.alignment: Qt.AlignCenter
0058         focusReason : Qt.PopupFocusReason
0059         placeholderText: i18n("Search %1 contacts", _contactsList.count)
0060         onAccepted: _contactsModel.filter = text
0061         onCleared: _contactsModel.filter = ""
0062     }
0063 
0064     gridView.itemSize: Math.min(140, Math.floor(width/3))
0065 
0066     listView.spacing: Maui.Style.space.big
0067     listView.flickable.header: Item
0068     {
0069         visible: showAccountFilter
0070         height: visible ? Maui.Style.toolBarHeight * 1.5 : 0
0071         width: visible ? parent.width : 0
0072 
0073         ComboBox
0074         {
0075             id: _accountsCombobox
0076             width: isWide ? control.width * 0.8 : control.width * 0.95
0077             textRole: "account"
0078             anchors.centerIn: parent
0079 
0080             onActivated:
0081             {
0082 
0083                 console.log("filter by:"+currentText)
0084                 if(currentText === "All")
0085                     list.reset()
0086                 else
0087                     list.query = "account="+currentText
0088 
0089                 positionViewAtBeginning()
0090             }
0091 
0092             Component.onCompleted:
0093             {
0094                 var androidAccounts = [{account: "All"}]
0095                 var accounts = []
0096                 accounts = list.getAccounts()
0097 
0098                 for(var i in accounts)
0099                     androidAccounts.push(accounts[i])
0100                 _accountsCombobox.model = androidAccounts;
0101             }
0102 
0103         }
0104 
0105     }
0106 
0107     listView.section.property: "n"
0108     listView.section.criteria: ViewSection.FirstCharacter
0109     listView.section.labelPositioning: ViewSection.InlineLabels
0110     listView.section.delegate: Maui.LabelDelegate
0111     {
0112         label: section.toUpperCase()
0113         isSection: true
0114         width: parent.width
0115         opacity: 0.6
0116     }
0117 
0118     gridDelegate: Item
0119     {
0120         width: control.gridView.cellWidth
0121         height: control.gridView.cellHeight
0122 
0123         property bool isCurrentItem : GridView.isCurrentItem
0124 
0125         GridContactDelegate
0126         {
0127             anchors.fill: parent
0128             anchors.margins: Maui.Style.space.medium
0129             isCurrentItem: parent.isCurrentItem
0130 
0131             onClicked:
0132             {
0133                 control.currentIndex = index
0134 
0135                 if(Maui.Handy.singleClick)
0136                 {
0137                     openContact(_contactsModel.get(index))
0138                 }
0139             }
0140 
0141             onDoubleClicked:
0142             {
0143                 control.currentIndex = index
0144 
0145                 if(!Maui.Handy.singleClick)
0146                 {
0147                     openContact(_contactsModel.get(index))
0148                 }
0149             }
0150 
0151             onFavClicked:
0152             {
0153                 var item = _contactsList.get(index)
0154                 item["fav"] = item.fav == "1" ? "0" : "1"
0155                 _contactsList.update(item, listModel.mappedToSource(index))
0156             }
0157         }
0158     }
0159 
0160     listDelegate: ContactDelegate
0161     {
0162         height: 60
0163         width: Math.min(isWide ? ListView.view.width * 0.8 : ListView.view.width, 500)
0164         anchors.horizontalCenter: parent.horizontalCenter
0165         showQuickActions: true
0166         template.headerSizeHint: 60
0167 
0168         template.iconComponent: Item
0169         {
0170             id: _contactPic
0171 
0172             Rectangle
0173             {
0174                 Maui.Theme.colorSet: Maui.Theme.Complementary
0175                 Maui.Theme.inherit: false
0176                 anchors.fill: parent
0177                 radius: Maui.Style.radiusV
0178                 color: Maui.Theme.backgroundColor
0179 
0180                 Loader
0181                 {
0182                     id: _contactPicLoader
0183                     anchors.fill: parent
0184                     anchors.margins: 1
0185                     sourceComponent: model.photo ? _imgComponent : _iconComponent
0186                 }
0187 
0188                 Component
0189                 {
0190                     id: _imgComponent
0191 
0192                     Image
0193                     {
0194                         id: _img
0195 
0196                         sourceSize.width: parent.width
0197                         sourceSize.height: parent.height
0198 
0199                         fillMode: Image.PreserveAspectCrop
0200                         cache: true
0201                         antialiasing: true
0202                         smooth: true
0203                         asynchronous: true
0204 
0205                         source:  "image://contact/"+ model.id
0206 
0207                         layer.enabled: true
0208                         layer.effect: OpacityMask
0209                         {
0210                             maskSource: Item
0211                             {
0212                                 width: _img.width
0213                                 height: _img.height
0214 
0215                                 Rectangle
0216                                 {
0217                                     anchors.fill: parent
0218                                     radius: Maui.Style.radiusV
0219                                 }
0220                             }
0221                         }
0222                     }
0223                 }
0224 
0225                 Component
0226                 {
0227                     id: _iconComponent
0228 
0229                     Label
0230                     {
0231                         anchors.fill: parent
0232                         horizontalAlignment: Qt.AlignHCenter
0233                         verticalAlignment: Qt.AlignVCenter
0234                         color: Maui.Theme.textColor
0235                         font.pointSize: Maui.Style.fontSizes.huge
0236                         font.bold: true
0237                         font.weight: Font.Bold
0238                         text: model.n ? model.n[0].toUpperCase() : "?"
0239                     }
0240                 }
0241             }
0242         }
0243 
0244         quickActions: [
0245 
0246             Action
0247             {
0248                 icon.name: "send-sms"
0249                 onTriggered:
0250                 {
0251                     _dialogLoader.sourceComponent =  _messageComposerComponent
0252                     dialog.contact = list.get(index)
0253                     dialog.open()
0254                 }
0255             },
0256 
0257             Action
0258             {
0259                 enabled: Maui.Handy.isMobile
0260                 icon.name: "dialer-call"
0261                 onTriggered:  _communicator.call(model.tel)
0262 
0263             }
0264         ]
0265 
0266         onClicked:
0267         {
0268             control.currentIndex = index
0269 
0270             if(Maui.Handy.singleClick)
0271             {
0272                 openContact(_contactsModel.get(index))
0273             }
0274         }
0275 
0276         onDoubleClicked:
0277         {
0278             control.currentIndex = index
0279 
0280             if(!Maui.Handy.singleClick)
0281             {
0282                 openContact(_contactsModel.get(index))
0283             }
0284         }
0285 
0286         onFavClicked:
0287         {
0288             var item = _contactsList.get(index)
0289             item["fav"] = item.fav == "1" ? "0" : "1"
0290             _contactsList.update(item, listModel.mappedToSource(index))
0291         }
0292     }
0293 
0294 
0295     Component
0296     {
0297         id: _contactPageComponent
0298 
0299         ContactPage
0300         {
0301             id: _contactPage
0302             contact: control.currentContact
0303             onCloseTriggered:
0304             {
0305                 if(editing)
0306                 {
0307                     _confirmExit.open()
0308 
0309                 }else
0310                 {
0311                     close()
0312                 }
0313             }
0314 
0315             Maui.InfoDialog
0316             {
0317                 id: _confirmExit
0318                 title: i18n("Discard")
0319                 message: i18n("If you chose to exit the changes made will be lost. Do you want to exit?")
0320 
0321                 onAccepted: close()
0322                 onRejected:
0323                 {
0324                     _contactPage.editing = false
0325 
0326                     if(!_contactPage.contact.id)
0327                     {
0328                         _contactPage.close()
0329                     }
0330 
0331                     _confirmExit.close()
0332                 }
0333 
0334             }
0335 
0336             onEditCanceled:
0337             {
0338                 if(!contact.id)
0339                 {
0340                     _contactPage.close()
0341                 }
0342             }
0343 
0344             onContactEdited:
0345             {
0346                 console.log(contact.id)
0347 
0348                 if(contact.n.length && contact.tel.length)
0349                 {
0350                     if(contact.id)
0351                     {
0352                         _contactsList.update(contact, listModel.mappedToSource(control.currentIndex))
0353                     }else
0354                     {
0355                         _contactsList.insert(contact)
0356                         notify("list-add-user", i18n("New contact added"), contact.n)
0357                     }
0358                 }else
0359                 {
0360                     _contactPage.close()
0361                 }
0362             }
0363         }
0364     }
0365 
0366     function openContact(contact)
0367     {
0368         control.currentContact = contact
0369         _dialogLoader.sourceComponent = _contactPageComponent
0370         dialog.open()
0371     }
0372 
0373 }
0374