MainWindow.qml 6.46 KB
Newer Older
Ronan's avatar
Ronan committed
1 2 3 4
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3

Ronan's avatar
Ronan committed
5 6 7
// Explicit import to support Toolbar.
import QtQuick.Controls 1.4 as Controls1

Ronan's avatar
Ronan committed
8 9 10 11 12 13
import Common 1.0
import Linphone 1.0
import Utils 1.0

import App.Styles 1.0

Ronan's avatar
Ronan committed
14
// =============================================================================
Ronan's avatar
Ronan committed
15

Ronan's avatar
Ronan committed
16
Controls1.ApplicationWindow {
Ronan's avatar
Ronan committed
17 18
  id: window

19
  property string _currentView
20 21 22 23 24 25 26 27 28 29 30 31
  property var _lockedInfo

  // ---------------------------------------------------------------------------

  function lockView (info) {
    _lockedInfo = info
  }

  function unlockView () {
    _lockedInfo = undefined
  }

32
  function setView (view, props) {
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    if (!_lockedInfo) {
      _setView(view, props)
      return
    }

    Utils.openConfirmDialog(window, {
      descriptionText: _lockedInfo.descriptionText,
      exitHandler: function (status) {
        if (status) {
          unlockView()
          _setView(view, props)
        } else {
          _updateSelectedEntry(_currentView, props)
        }
      },
      title: _lockedInfo.title
    })
  }

  // ---------------------------------------------------------------------------

  function _updateSelectedEntry (view, props) {
Ronan's avatar
Ronan committed
55 56 57 58 59 60
    if (view === 'Home' || view === 'Contacts') {
      menu.setSelectedEntry(view === 'Home' ? 0 : 1)
      timeline.resetSelectedEntry()
    } else if (view === 'Conversation') {
      menu.resetSelectedEntry()
      timeline.setSelectedEntry(props.sipAddress)
61 62 63
    } else if (view === 'ContactEdit') {
      menu.resetSelectedEntry()
      timeline.resetSelectedEntry()
Ronan's avatar
Ronan committed
64
    }
Ronan's avatar
Ronan committed
65 66
  }

67
  function _setView (view, props) {
68
    window.show()
69 70 71
    window.requestActivate()
    collapse.setCollapsed(true)

72 73 74
    _updateSelectedEntry(view, props)
    _currentView = view
    contentLoader.setSource(view + '.qml', props || {})
Ronan's avatar
Ronan committed
75 76
  }

Ronan's avatar
Ronan committed
77
  // ---------------------------------------------------------------------------
Ronan's avatar
Ronan committed
78
  // Window properties.
Ronan's avatar
Ronan committed
79
  // ---------------------------------------------------------------------------
Ronan's avatar
Ronan committed
80 81 82 83

  maximumHeight: MainWindowStyle.toolBar.height
  minimumHeight: MainWindowStyle.toolBar.height
  minimumWidth: MainWindowStyle.minimumWidth
84 85 86

  width: MainWindowStyle.width

Ronan's avatar
Ronan committed
87 88 89
  title: MainWindowStyle.title
  visible: true

Ronan's avatar
Ronan committed
90
  // ---------------------------------------------------------------------------
91
  // Menu bar.
Ronan's avatar
Ronan committed
92
  // ---------------------------------------------------------------------------
Ronan's avatar
Ronan committed
93

94 95 96 97 98 99 100 101 102 103 104
  menuBar: MainWindowMenuBar {
    hide: !collapse.isCollapsed
  }

  // ---------------------------------------------------------------------------

  Component.onCompleted: _setView('Home')

  onActiveFocusItemChanged: activeFocusItem == null && smartSearchBar.hideMenu()

  // ---------------------------------------------------------------------------
Ronan's avatar
Ronan committed
105

Ronan's avatar
Ronan committed
106
  ColumnLayout {
107 108
    id: container

Ronan's avatar
Ronan committed
109 110
    anchors.fill: parent
    spacing: 0
Ronan's avatar
Ronan committed
111

Ronan's avatar
Ronan committed
112 113 114
    // -------------------------------------------------------------------------
    // Toolbar properties.
    // -------------------------------------------------------------------------
Ronan's avatar
Ronan committed
115

Ronan's avatar
Ronan committed
116 117 118
    ToolBar {
      Layout.fillWidth: true
      Layout.preferredHeight: MainWindowStyle.toolBar.height
Ronan's avatar
Ronan committed
119

Ronan's avatar
Ronan committed
120
      background: MainWindowStyle.toolBar.background
Ronan's avatar
Ronan committed
121

Ronan's avatar
Ronan committed
122 123 124 125 126 127 128
      RowLayout {
        anchors {
          fill: parent
          leftMargin: MainWindowStyle.toolBar.leftMargin
          rightMargin: MainWindowStyle.toolBar.rightMargin
        }
        spacing: MainWindowStyle.toolBar.spacing
Ronan's avatar
Ronan committed
129

Ronan's avatar
Ronan committed
130 131
        Collapse {
          id: collapse
132

Ronan's avatar
Ronan committed
133 134 135
          Layout.fillHeight: parent.height
          target: window
          targetHeight: MainWindowStyle.minimumHeight
136 137
        }

Ronan's avatar
Ronan committed
138 139 140 141 142
        AccountStatus {
          id: accountStatus

          Layout.fillHeight: parent.height
          Layout.preferredWidth: MainWindowStyle.accountStatus.width
143

Ronan's avatar
Ronan committed
144
          account: AccountSettingsModel
Ronan's avatar
test  
Ronan committed
145

Ronan's avatar
Ronan committed
146 147 148 149 150
          TooltipArea {
            text: AccountSettingsModel.sipAddress
          }

          onClicked: Utils.openWindow('ManageAccounts', window)
151 152
        }

Ronan's avatar
Ronan committed
153 154 155 156 157 158 159 160 161 162 163 164
        Column {
          width: MainWindowStyle.autoAnswerStatus.width

          Icon {
            icon: SettingsModel.autoAnswerStatus
              ? 'auto_answer'
              : ''
            iconSize: MainWindowStyle.autoAnswerStatus.iconSize
          }

          Text {
            clip: true
165 166
            color: MainWindowStyle.autoAnswerStatus.text.color
            font.pointSize: MainWindowStyle.autoAnswerStatus.text.fontSize
Ronan's avatar
Ronan committed
167 168
            text: qsTr('autoAnswerStatus')
            width: parent.width
169 170 171
          }
        }

Ronan's avatar
Ronan committed
172 173
        SmartSearchBar {
          id: smartSearchBar
Ronan's avatar
Ronan committed
174

Ronan's avatar
Ronan committed
175 176 177 178
          Layout.fillWidth: true
          entryHeight: MainWindowStyle.searchBox.entryHeight
          maxMenuHeight: MainWindowStyle.searchBox.maxHeight
          placeholderText: qsTr('mainSearchBarPlaceholder')
Ronan's avatar
Ronan committed
179

Ronan's avatar
Ronan committed
180
          model: SmartSearchBarModel {}
181

Ronan's avatar
Ronan committed
182 183 184
          onAddContact: window.setView('ContactEdit', {
            sipAddress: sipAddress
          })
Ronan's avatar
Ronan committed
185

Ronan's avatar
Ronan committed
186 187 188 189
          onLaunchCall: CallsListModel.launchAudioCall(sipAddress)
          onLaunchChat: window.setView('Conversation', {
            sipAddress: sipAddress
          })
190

Ronan's avatar
Ronan committed
191
          onLaunchVideoCall: CallsListModel.launchVideoCall(sipAddress)
192

Ronan's avatar
Ronan committed
193 194 195 196
          onEntryClicked: window.setView(entry.contact ? 'ContactEdit' : 'Conversation', {
            sipAddress: entry.sipAddress
          })
        }
Ronan's avatar
Ronan committed
197 198 199
      }
    }

Ronan's avatar
Ronan committed
200 201 202
    // -------------------------------------------------------------------------
    // Content.
    // -------------------------------------------------------------------------
Ronan's avatar
Ronan committed
203

Ronan's avatar
Ronan committed
204
    RowLayout {
Ronan's avatar
Ronan committed
205
      Layout.fillHeight: true
Ronan's avatar
Ronan committed
206 207
      Layout.fillWidth: true

Ronan's avatar
Ronan committed
208
      spacing: 0
Ronan's avatar
Ronan committed
209

Ronan's avatar
Ronan committed
210 211 212 213
      // Main menu.
      ColumnLayout {
        Layout.maximumWidth: MainWindowStyle.menu.width
        Layout.preferredWidth: MainWindowStyle.menu.width
Ronan's avatar
Ronan committed
214

Ronan's avatar
Ronan committed
215
        spacing: 0
Ronan's avatar
test  
Ronan committed
216

Ronan's avatar
Ronan committed
217 218
        Menu {
          id: menu
Ronan's avatar
Ronan committed
219

Ronan's avatar
Ronan committed
220 221
          entryHeight: MainWindowStyle.menu.entryHeight
          entryWidth: MainWindowStyle.menu.width
Ronan's avatar
Ronan committed
222

Ronan's avatar
Ronan committed
223 224 225 226 227 228 229
          entries: [{
            entryName: qsTr('homeEntry'),
            icon: 'home'
          }, {
            entryName: qsTr('contactsEntry'),
            icon: 'contact'
          }]
Ronan's avatar
Ronan committed
230

Ronan's avatar
Ronan committed
231 232 233 234 235 236 237 238 239 240
          onEntrySelected: !entry ? setView('Home') : setView('Contacts')
        }

        // History.
        Timeline {
          id: timeline

          Layout.fillHeight: true
          Layout.fillWidth: true
          model: TimelineModel
Ronan's avatar
Ronan committed
241

Ronan's avatar
Ronan committed
242 243
          onEntrySelected: setView('Conversation', { sipAddress: entry })
        }
Ronan's avatar
test  
Ronan committed
244
      }
245

Ronan's avatar
Ronan committed
246 247 248
      // Main content.
      Loader {
        id: contentLoader
249

Ronan's avatar
Ronan committed
250 251 252
        Layout.fillHeight: true
        Layout.fillWidth: true
      }
253
    }
Ronan's avatar
Ronan committed
254 255
  }
}