From 370d07c14b9cb14bf715e99c17a6fb3fc4b588e9 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 7 Dec 2016 15:42:33 +0100 Subject: [PATCH] feat(views/App/MainWindow/ContactEdit): view in progress --- tests/CMakeLists.txt | 2 +- tests/assets/languages/en.ts | 8 +- tests/assets/languages/fr.ts | 8 +- .../src/components/contacts/ContactModel.cpp | 76 +++++++++++++++++-- .../src/components/contacts/ContactModel.hpp | 40 ++++++++++ tests/ui/modules/Common/Form/ListForm.qml | 38 ++++++---- tests/ui/views/App/MainWindow/ContactEdit.qml | 27 ++++--- 7 files changed, 161 insertions(+), 38 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ee0e9e4ce..90f11fd83 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,7 +29,7 @@ set(CUSTOM_FLAGS "\ -Wunused \ ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CUSTOM_FLAGS}") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG") # -------------------------------------------------------------------- # Define packages, libs, sources, headers, resources and languages diff --git a/tests/assets/languages/en.ts b/tests/assets/languages/en.ts index e18fe2523..1dc3b3364 100644 --- a/tests/assets/languages/en.ts +++ b/tests/assets/languages/en.ts @@ -116,11 +116,11 @@ address - ADDRESS + ADDRESS addressInput - Address + Address emails @@ -132,11 +132,11 @@ webSites - WEB SITE(S) + WEB SITE(S) webSitesInput - URL + URL avatarChooserTitle diff --git a/tests/assets/languages/fr.ts b/tests/assets/languages/fr.ts index 3291f13a3..adca4ffbd 100644 --- a/tests/assets/languages/fr.ts +++ b/tests/assets/languages/fr.ts @@ -108,11 +108,11 @@ address - ADRESSE(S) + ADRESSE(S) addressInput - Adresse + Adresse emails @@ -124,11 +124,11 @@ webSites - SITE(S) WEB + SITE(S) WEB webSitesInput - URL + URL avatarChooserTitle diff --git a/tests/src/components/contacts/ContactModel.cpp b/tests/src/components/contacts/ContactModel.cpp index 2f7508e3c..3f15e71ec 100644 --- a/tests/src/components/contacts/ContactModel.cpp +++ b/tests/src/components/contacts/ContactModel.cpp @@ -22,13 +22,7 @@ ContactModel::ContactModel (shared_ptr linphone_friend) { m_linphone_friend = linphone_friend; } -Presence::PresenceStatus ContactModel::getPresenceStatus () const { - return m_presence_status; -} - -Presence::PresenceLevel ContactModel::getPresenceLevel () const { - return Presence::getPresenceLevel(m_presence_status); -} +// ------------------------------------------------------------------- QString ContactModel::getUsername () const { return Utils::linphoneStringToQString( @@ -45,6 +39,8 @@ bool ContactModel::setUsername (const QString &username) { ); } +// ------------------------------------------------------------------- + QString ContactModel::getAvatar () const { // Find desktop avatar. list > photos = @@ -123,6 +119,8 @@ bool ContactModel::setAvatar (const QString &path) { return true; } +// ------------------------------------------------------------------- + QVariantList ContactModel::getSipAddresses () const { QVariantList list; @@ -133,9 +131,73 @@ QVariantList ContactModel::getSipAddresses () const { } void ContactModel::setSipAddresses (const QVariantList &sip_addresses) { + // TODO. +} + +// ------------------------------------------------------------------- + +QVariantList ContactModel::getCompanies () const { + QVariantList list; + + for (const auto &company : m_linphone_friend->getVcard()->getBelcard()->getOrganizations()) + list.append(Utils::linphoneStringToQString(company->getValue())); + + return list; +} + +void ContactModel::setCompanies (const QVariantList &companies) { + // TODO. +} + +// ------------------------------------------------------------------- + +QVariantList ContactModel::getEmails () const { + QVariantList list; + + for (const auto &email : m_linphone_friend->getVcard()->getBelcard()->getEmails()) + list.append(Utils::linphoneStringToQString(email->getValue())); + + return list; +} + +void ContactModel::setEmails (const QVariantList &emails) { + // TODO. +} + +// ------------------------------------------------------------------- + +QVariantList ContactModel::getUrls () const { + QVariantList list; + + for (const auto &url : m_linphone_friend->getVcard()->getBelcard()->getURLs()) + list.append(Utils::linphoneStringToQString(url->getValue())); + + return list; +} + +void ContactModel::setUrls (const QVariantList &urls) { + // TODO. +} + +// ------------------------------------------------------------------- + +QList ContactModel::getAddresses () const { } +void ContactModel::setAddresses (const QList &addresses) { + +} + +// ------------------------------------------------------------------- + +Presence::PresenceStatus ContactModel::getPresenceStatus () const { + return m_presence_status; +} + +Presence::PresenceLevel ContactModel::getPresenceLevel () const { + return Presence::getPresenceLevel(m_presence_status); +} QString ContactModel::getSipAddress () const { return Utils::linphoneStringToQString( m_linphone_friend->getAddress()->asString() diff --git a/tests/src/components/contacts/ContactModel.hpp b/tests/src/components/contacts/ContactModel.hpp index 0e647a67a..3768fa382 100644 --- a/tests/src/components/contacts/ContactModel.hpp +++ b/tests/src/components/contacts/ContactModel.hpp @@ -35,6 +35,34 @@ class ContactModel : public QObject { NOTIFY contactUpdated ); + Q_PROPERTY( + QVariantList companies + READ getCompanies + WRITE setCompanies + NOTIFY contactUpdated + ); + + Q_PROPERTY( + QVariantList emails + READ getEmails + WRITE setEmails + NOTIFY contactUpdated + ); + + Q_PROPERTY( + QVariantList urls + READ getUrls + WRITE setUrls + NOTIFY contactUpdated + ); + + Q_PROPERTY( + QList addresses + READ getAddresses + WRITE setAddresses + NOTIFY contactUpdated + ); + Q_PROPERTY( Presence::PresenceStatus presenceStatus READ getPresenceStatus @@ -69,6 +97,18 @@ private: QVariantList getSipAddresses () const; void setSipAddresses (const QVariantList &sip_addresses); + QVariantList getCompanies () const; + void setCompanies (const QVariantList &companies); + + QVariantList getEmails () const; + void setEmails (const QVariantList &emails); + + QVariantList getUrls () const; + void setUrls (const QVariantList &urls); + + QList getAddresses () const; + void setAddresses (const QList &addresses); + Presence::PresenceStatus getPresenceStatus () const; Presence::PresenceLevel getPresenceLevel () const; diff --git a/tests/ui/modules/Common/Form/ListForm.qml b/tests/ui/modules/Common/Form/ListForm.qml index 7b4a8f773..5ec2c6b8b 100644 --- a/tests/ui/modules/Common/Form/ListForm.qml +++ b/tests/ui/modules/Common/Form/ListForm.qml @@ -11,6 +11,7 @@ RowLayout { property alias placeholder: placeholder.text property alias title: text.text + property var defaultData: [] // ----------------------------------------------------------------- @@ -24,10 +25,8 @@ RowLayout { function _handleEditionFinished (index, text) { if (text.length === 0) { - console.log('edition end') values.model.remove(index) } else { - console.log('edition end (text exists)') values.model.set(index, { $value: text }) } @@ -87,10 +86,7 @@ RowLayout { } padding: ListFormStyle.value.text.padding - visible: { - console.log('placeholder', values.model.count) - return values.model.count === 0 - } + visible: values.model.count === 0 verticalAlignment: Text.AlignVCenter } @@ -104,10 +100,7 @@ RowLayout { Layout.fillWidth: true Layout.preferredHeight: count * ListFormStyle.lineHeight interactive: false - visible: { - console.log('values', model.count) - return model.count > 0 - } + visible: model.count > 0 delegate: Item { implicitHeight: textEdit.height @@ -150,14 +143,33 @@ RowLayout { Component.onCompleted: { if ($value.length === 0) { + // Magic code. If it's the first inserted value, + // an event or a callback steal the item focus. + // I suppose it's an internal Qt qml event... + // + // So, I choose to run a callback executed after this + // internal event. + Utils.setTimeout(listForm, 0, function () { textEdit.forceActiveFocus() + }) } } } - model: ListModel { - ListElement { $value: 'merinos@sip.linphone.org' } - ListElement { $value: 'elisabeth.pro@sip.linphone.org' } + model: ListModel {} + + // --------------------------------------------------------------- + // Init values. + // --------------------------------------------------------------- + + Component.onCompleted: { + if (!defaultData) { + return + } + + defaultData.forEach(function (data) { + model.append({ $value: data }) + }) } } } diff --git a/tests/ui/views/App/MainWindow/ContactEdit.qml b/tests/ui/views/App/MainWindow/ContactEdit.qml index 538f8df39..f21552a9a 100644 --- a/tests/ui/views/App/MainWindow/ContactEdit.qml +++ b/tests/ui/views/App/MainWindow/ContactEdit.qml @@ -154,24 +154,33 @@ ColumnLayout { anchors.right: parent.right ListForm { - title: qsTr('sipAccounts') placeholder: qsTr('sipAccountsInput') - } + title: qsTr('sipAccounts') - ListForm { - title: qsTr('address') - placeholder: qsTr('addressInput') + defaultData: _contact.sipAddresses } ListForm { title: qsTr('emails') placeholder: qsTr('emailsInput') - } - ListForm { - title: qsTr('webSites') - placeholder: qsTr('webSitesInput') + defaultData: _contact.emails } } } } + + + /************************************************/ + + /* ListForm { */ + /* title: qsTr('address') */ + /* placeholder: qsTr('addressInput') */ + /* } */ + /* */ + /* */ + /* ListForm { */ + /* title: qsTr('webSites') */ + /* placeholder: qsTr('webSitesInput') */ + /* } */ + /************************************************/