ContactEdit.qml 8.35 KB
Newer Older
1
import QtQuick 2.7
2
import QtQuick.Controls 2.2
3
import QtQuick.Dialogs 1.2
4 5 6 7
import QtQuick.Layouts 1.3

import Common 1.0
import Linphone 1.0
8
import Linphone.Styles 1.0
9 10 11

import App.Styles 1.0

Ronan's avatar
Ronan committed
12 13
import 'ContactEdit.js' as Logic

14
// =============================================================================
15 16 17 18

ColumnLayout  {
  id: contactEdit

19
  property string sipAddress
20

21 22
  readonly property alias vcard: contactEdit._vcard

23
  property bool _edition: false
Ronan's avatar
Ronan committed
24
  property var _contact
25
  property var _vcard
26

27 28
  // ---------------------------------------------------------------------------

29 30
  spacing: 0

Ronan's avatar
Ronan committed
31
  Component.onCompleted: Logic.handleCreation()
32 33

  onVcardChanged: Logic.handleVcardChanged(vcard)
34 35

  // ---------------------------------------------------------------------------
Ronan's avatar
Ronan committed
36

37 38 39 40 41
  Loader {
    active: contactEdit._contact != null
    sourceComponent: Connections {
      target: contactEdit._contact

42
      onContactUpdated: Logic.handleContactUpdated()
43 44 45
    }
  }

46 47 48 49 50 51
  FileDialog {
    id: avatarChooser

    folder: shortcuts.home
    title: qsTr('avatarChooserTitle')

Ronan's avatar
Ronan committed
52
    onAccepted: Logic.setAvatar(fileUrls[0])
53 54
  }

55
  // ---------------------------------------------------------------------------
56
  // Info bar.
57
  // ---------------------------------------------------------------------------
58 59

  Rectangle {
60 61
    id: infoBar

62
    Layout.fillWidth: true
63 64
    Layout.preferredHeight: ContactEditStyle.bar.height
    color: ContactEditStyle.bar.color
65 66 67 68

    RowLayout {
      anchors {
        fill: parent
69 70
        leftMargin: ContactEditStyle.bar.leftMargin
        rightMargin: ContactEditStyle.bar.rightMargin
71 72
      }

73
      spacing: ContactEditStyle.bar.spacing
74

75
      ActionButton {
76
        enabled: _edition
77
        icon: 'contact_card_photo'
78
        iconSize: ContactEditStyle.bar.avatarSize
79 80

        onClicked: avatarChooser.open()
Ronan's avatar
Ronan committed
81 82 83 84 85

        Avatar {
          id: avatar

          anchors.fill: parent
86
          image: _vcard.avatar
87
          username: _vcard.username
88
          presenceLevel: _contact ? _contact.presenceLevel : -1
89
          visible: (isLoaded() && !parent.hovered) || !_edition
Ronan's avatar
Ronan committed
90
        }
91 92
      }

93
      TransparentTextInput {
Ronan's avatar
Ronan committed
94
        id: usernameInput
95

96
        Layout.fillWidth: true
97
        Layout.preferredHeight: ContactEditStyle.bar.buttons.size
98

99
        color: ContactEditStyle.bar.username.color
100 101 102

        font {
          bold: true
103
          pointSize: ContactEditStyle.bar.username.pointSize
104
        }
105 106
        forceFocus: true
        readOnly: !_edition
107
        text: avatar.username
108

Ronan's avatar
Ronan committed
109
        onEditingFinished: Logic.setUsername(text)
110 111
        onReadOnlyChanged: {
          if (!readOnly) {
112
            forceActiveFocus()
113 114
          }
        }
115 116
      }

117
      Row {
118
        Layout.alignment: Qt.AlignRight
119 120 121
        Layout.fillHeight: true

        spacing: ContactEditStyle.bar.actions.spacing
122
        visible: _contact != null
123

124 125 126
        ActionBar {
          anchors.verticalCenter: parent.verticalCenter
          iconSize: ContactEditStyle.bar.actions.history.iconSize
127

128 129
          ActionButton {
            icon: 'history'
130

131
            onClicked: sipAddressesMenu.open()
132
          }
133 134
        }

135 136 137 138 139 140 141 142
        ActionBar {
          anchors.verticalCenter: parent.verticalCenter

          ActionButton {
            icon: 'edit'
            iconSize: ContactEditStyle.bar.actions.edit.iconSize

            visible: !_edition
Ronan's avatar
Ronan committed
143
            onClicked: Logic.editContact()
144 145 146 147 148
          }

          ActionButton {
            icon: 'delete'
            iconSize: ContactEditStyle.bar.actions.del.iconSize
149

Ronan's avatar
Ronan committed
150
            onClicked: Logic.removeContact()
151
          }
152 153 154 155 156
        }
      }
    }
  }

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
  // ---------------------------------------------------------------------------

  SipAddressesMenu {
    id: sipAddressesMenu

    relativeTo: infoBar
    relativeX: infoBar.width - SipAddressesMenuStyle.entry.width
    relativeY: infoBar.height

    sipAddresses: _contact ? _contact.vcard.sipAddresses : [ contactEdit.sipAddress ]

    onSipAddressClicked: window.setView('Conversation', {
      sipAddress: sipAddress
    })
  }

173
  // ---------------------------------------------------------------------------
174
  // Info list.
175
  // ---------------------------------------------------------------------------
176

177
  Rectangle {
178 179
    Layout.fillHeight: true
    Layout.fillWidth: true
180

181
    color: ContactEditStyle.content.color
182

183 184
    Flickable {
      id: flick
185

186
      ScrollBar.vertical: ForceScrollBar {}
187

188 189 190 191 192 193
      anchors.fill: parent
      boundsBehavior: Flickable.StopAtBounds
      clip: true
      contentHeight: infoList.height
      contentWidth: width - ScrollBar.vertical.width
      flickableDirection: Flickable.VerticalFlick
194

195
      // -----------------------------------------------------------------------
Ronan's avatar
Ronan committed
196

197 198
      ColumnLayout {
        id: infoList
199

200
        width: flick.contentWidth
201

202 203
        ListForm {
          id: addresses
204

205 206 207
          Layout.leftMargin: ContactEditStyle.values.leftMargin
          Layout.rightMargin: ContactEditStyle.values.rightMargin
          Layout.topMargin: ContactEditStyle.values.topMargin
208

209 210 211 212
          minValues: _contact ? 1 : 0
          placeholder: qsTr('sipAccountsPlaceholder')
          readOnly: !_edition
          title: qsTr('sipAccounts')
213

214
          onChanged: Logic.handleSipAddressChanged(addresses, index, oldValue, newValue)
215 216
          onRemoved: _vcard.removeSipAddress(value)
        }
Ronan's avatar
Ronan committed
217

218 219 220 221 222
        Rectangle {
          Layout.fillWidth: true
          Layout.preferredHeight: ContactEditStyle.values.separator.height
          color: ContactEditStyle.values.separator.color
        }
223

224 225
        ListForm {
          id: companies
226

227 228
          Layout.leftMargin: ContactEditStyle.values.leftMargin
          Layout.rightMargin: ContactEditStyle.values.rightMargin
229

230 231 232
          placeholder: qsTr('companiesPlaceholder')
          readOnly: !_edition
          title: qsTr('companies')
233

234
          onChanged: Logic.handleCompanyChanged(companies, index, oldValue, newValue)
235 236
          onRemoved: _vcard.removeCompany(value)
        }
237

238 239 240 241 242
        Rectangle {
          Layout.fillWidth: true
          Layout.preferredHeight: ContactEditStyle.values.separator.height
          color: ContactEditStyle.values.separator.color
        }
243

244 245
        ListForm {
          id: emails
246

247 248
          Layout.leftMargin: ContactEditStyle.values.leftMargin
          Layout.rightMargin: ContactEditStyle.values.rightMargin
249

250 251 252
          placeholder: qsTr('emailsPlaceholder')
          readOnly: !_edition
          title: qsTr('emails')
253

254
          onChanged: Logic.handleEmailChanged(emails, index, oldValue, newValue)
255 256
          onRemoved: _vcard.removeEmail(value)
        }
257

258 259 260 261 262
        Rectangle {
          Layout.fillWidth: true
          Layout.preferredHeight: ContactEditStyle.values.separator.height
          color: ContactEditStyle.values.separator.color
        }
263

264 265
        ListForm {
          id: urls
266

267 268
          Layout.leftMargin: ContactEditStyle.values.leftMargin
          Layout.rightMargin: ContactEditStyle.values.rightMargin
269

270 271 272
          placeholder: qsTr('webSitesPlaceholder')
          readOnly: !_edition
          title: qsTr('webSites')
273

274
          onChanged: Logic.handleUrlChanged(urls, index, oldValue, newValue)
275 276
          onRemoved: _vcard.removeUrl(value)
        }
277

278 279 280 281 282
        Rectangle {
          Layout.fillWidth: true
          Layout.preferredHeight: ContactEditStyle.values.separator.height
          color: ContactEditStyle.values.separator.color
        }
283

284 285 286
        StaticListForm {
          Layout.leftMargin: ContactEditStyle.values.leftMargin
          Layout.rightMargin: ContactEditStyle.values.rightMargin
287

288
          fields: Logic.buildAddressFields()
289

290 291
          readOnly: !_edition
          title: qsTr('address')
292

293 294
          onChanged: Logic.handleAddressChanged(index, value)
        }
295

296 297 298
        // ---------------------------------------------------------------------
        // Edition buttons.
        // ---------------------------------------------------------------------
299

300 301 302 303
        Row {
          Layout.alignment: Qt.AlignHCenter
          Layout.bottomMargin: ContactEditStyle.values.bottomMargin
          Layout.topMargin: ContactEditStyle.buttons.topMargin
304

305 306
          spacing: ContactEditStyle.buttons.spacing
          visible: _edition
307

308 309 310
          TextButtonA {
            text: qsTr('cancel')
            onClicked: Logic.cancel()
311
          }
312

313 314 315 316
          TextButtonB {
            enabled: usernameInput.text.length > 0 && _vcard.sipAddresses.length > 0
            text: qsTr('save')
            onClicked: Logic.save()
317 318
          }
        }
319
      }
320 321 322
    }
  }
}