Skip to content
Snippets Groups Projects
Commit 948e2cc8 authored by Aline Gondim Santos's avatar Aline Gondim Santos
Browse files

callactionbar: avoid multiple resets

GitLab: #1073

Change-Id: I7dc2ab632170a959b8d29979deacd3fb03ff6671
parent b6116856
Branches
Tags
No related merge requests found
...@@ -35,10 +35,11 @@ IndexRangeFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& s ...@@ -35,10 +35,11 @@ IndexRangeFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& s
{ {
auto index = sourceModel()->index(sourceRow, 0, sourceParent); auto index = sourceModel()->index(sourceRow, 0, sourceParent);
bool predicate = true; bool predicate = true;
bool enabled = sourceModel()->data(index, CallControl::Role::Enabled).toBool();
if (filterRole() != Qt::DisplayRole) { if (filterRole() != Qt::DisplayRole) {
predicate = sourceModel()->data(index, filterRole()).toInt() != 0; predicate = sourceModel()->data(index, filterRole()).toInt() != 0;
} }
return sourceRow <= max_ && sourceRow >= min_ && predicate; return sourceRow <= max_ && sourceRow >= min_ && predicate && enabled;
} }
void void
...@@ -197,10 +198,12 @@ CallControlListModel::data(const QModelIndex& index, int role) const ...@@ -197,10 +198,12 @@ CallControlListModel::data(const QModelIndex& index, int role) const
auto item = data_.at(index.row()); auto item = data_.at(index.row());
switch (role) { switch (role) {
case Role::ItemAction: case CallControl::Role::ItemAction:
return QVariant::fromValue(item.itemAction); return QVariant::fromValue(item.itemAction);
case Role::UrgentCount: case CallControl::Role::UrgentCount:
return QVariant::fromValue(item.urgentCount); return QVariant::fromValue(item.urgentCount);
case CallControl::Role::Enabled:
return QVariant::fromValue(item.enabled);
} }
return QVariant(); return QVariant();
} }
...@@ -212,6 +215,7 @@ CallControlListModel::roleNames() const ...@@ -212,6 +215,7 @@ CallControlListModel::roleNames() const
QHash<int, QByteArray> roles; QHash<int, QByteArray> roles;
roles[ItemAction] = "ItemAction"; roles[ItemAction] = "ItemAction";
roles[UrgentCount] = "UrgentCount"; roles[UrgentCount] = "UrgentCount";
roles[Enabled] = "Enabled";
return roles; return roles;
} }
...@@ -232,6 +236,24 @@ CallControlListModel::setUrgentCount(QVariant item, int count) ...@@ -232,6 +236,24 @@ CallControlListModel::setUrgentCount(QVariant item, int count)
} }
} }
void
CallControlListModel::setEnabled(QObject* obj, bool enabled)
{
beginResetModel();
auto it = std::find_if(data_.cbegin(), data_.cend(), [obj](const auto& item) {
return item.itemAction == obj;
});
if (it != data_.cend()) {
auto row = std::distance(data_.cbegin(), it);
if (row >= rowCount())
return;
data_[row].enabled = enabled;
auto idx = index(row, 0);
Q_EMIT dataChanged(idx, idx);
}
endResetModel();
}
void void
CallControlListModel::addItem(const CallControl::Item& item) CallControlListModel::addItem(const CallControl::Item& item)
{ {
...@@ -264,15 +286,15 @@ CallOverlayModel::CallOverlayModel(LRCInstance* instance, QObject* parent) ...@@ -264,15 +286,15 @@ CallOverlayModel::CallOverlayModel(LRCInstance* instance, QObject* parent)
} }
void void
CallOverlayModel::addPrimaryControl(const QVariant& action) CallOverlayModel::addPrimaryControl(const QVariant& action, bool enabled)
{ {
primaryModel_->addItem(CallControl::Item {action.value<QObject*>()}); primaryModel_->addItem(CallControl::Item {action.value<QObject*>(), enabled});
} }
void void
CallOverlayModel::addSecondaryControl(const QVariant& action) CallOverlayModel::addSecondaryControl(const QVariant& action, bool enabled)
{ {
secondaryModel_->addItem(CallControl::Item {action.value<QObject*>()}); secondaryModel_->addItem(CallControl::Item {action.value<QObject*>(), enabled});
setControlRanges(); setControlRanges();
} }
...@@ -282,6 +304,13 @@ CallOverlayModel::setUrgentCount(QVariant row, int count) ...@@ -282,6 +304,13 @@ CallOverlayModel::setUrgentCount(QVariant row, int count)
secondaryModel_->setUrgentCount(row, count); secondaryModel_->setUrgentCount(row, count);
} }
void
CallOverlayModel::setEnabled(QObject* obj, bool enabled)
{
primaryModel_->setEnabled(obj, enabled);
secondaryModel_->setEnabled(obj, enabled);
}
QVariant QVariant
CallOverlayModel::primaryModel() CallOverlayModel::primaryModel()
{ {
...@@ -363,7 +392,8 @@ CallOverlayModel::eventFilter(QObject* object, QEvent* event) ...@@ -363,7 +392,8 @@ CallOverlayModel::eventFilter(QObject* object, QEvent* event)
void void
CallOverlayModel::setControlRanges() CallOverlayModel::setControlRanges()
{ {
auto count = secondaryModel_->rowCount();
overflowModel_->setRange(0, overflowIndex_); overflowModel_->setRange(0, overflowIndex_);
overflowVisibleModel_->setRange(overflowIndex_, secondaryModel_->rowCount()); overflowVisibleModel_->setRange(overflowIndex_, count);
overflowHiddenModel_->setRange(overflowIndex_ + 1, secondaryModel_->rowCount()); overflowHiddenModel_->setRange(overflowIndex_ + 1, count);
} }
...@@ -36,12 +36,13 @@ ...@@ -36,12 +36,13 @@
namespace CallControl { namespace CallControl {
Q_NAMESPACE Q_NAMESPACE
enum Role { ItemAction = Qt::UserRole + 1, UrgentCount }; enum Role { ItemAction = Qt::UserRole + 1, UrgentCount, Enabled};
Q_ENUM_NS(Role) Q_ENUM_NS(Role)
struct Item struct Item
{ {
QObject* itemAction; QObject* itemAction;
bool enabled {true};
int urgentCount {0}; int urgentCount {0};
}; };
} // namespace CallControl } // namespace CallControl
...@@ -106,6 +107,7 @@ public: ...@@ -106,6 +107,7 @@ public:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
void setUrgentCount(QVariant item, int count); void setUrgentCount(QVariant item, int count);
void setEnabled(QObject* obj, bool enabled);
void addItem(const CallControl::Item& item); void addItem(const CallControl::Item& item);
void clearData(); void clearData();
...@@ -121,9 +123,10 @@ class CallOverlayModel : public QObject ...@@ -121,9 +123,10 @@ class CallOverlayModel : public QObject
public: public:
CallOverlayModel(LRCInstance* instance, QObject* parent = nullptr); CallOverlayModel(LRCInstance* instance, QObject* parent = nullptr);
Q_INVOKABLE void addPrimaryControl(const QVariant& action); Q_INVOKABLE void addPrimaryControl(const QVariant& action, bool enabled);
Q_INVOKABLE void addSecondaryControl(const QVariant& action); Q_INVOKABLE void addSecondaryControl(const QVariant& action, bool enabled);
Q_INVOKABLE void setUrgentCount(QVariant item, int count); Q_INVOKABLE void setUrgentCount(QVariant item, int count);
Q_INVOKABLE void setEnabled(QObject* obj, bool enabled);
Q_INVOKABLE void clearControls(); Q_INVOKABLE void clearControls();
Q_INVOKABLE QVariant primaryModel(); Q_INVOKABLE QVariant primaryModel();
......
...@@ -43,6 +43,13 @@ CurrentCall::CurrentCall(LRCInstance* lrcInstance, QObject* parent) ...@@ -43,6 +43,13 @@ CurrentCall::CurrentCall(LRCInstance* lrcInstance, QObject* parent)
this, this,
&CurrentCall::onShowIncomingCallView); &CurrentCall::onShowIncomingCallView);
try {
auto& accInfo = lrcInstance_->getCurrentAccountInfo();
set_isSIP(accInfo.profileInfo.type == profile::Type::SIP);
} catch (const std::exception& e) {
qWarning() << "Can't update current call type" << e.what();
}
connectModel(); connectModel();
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import SortFilterProxyModel 0.2
import net.jami.Models 1.1 import net.jami.Models 1.1
import net.jami.Adapters 1.1 import net.jami.Adapters 1.1
import net.jami.Constants 1.1 import net.jami.Constants 1.1
...@@ -299,6 +300,8 @@ Control { ...@@ -299,6 +300,8 @@ Control {
text: !checked ? JamiStrings.muteCamera : JamiStrings.unmuteCamera text: !checked ? JamiStrings.muteCamera : JamiStrings.unmuteCamera
checked: !CurrentCall.isCapturing checked: !CurrentCall.isCapturing
property var menuAction: videoInputMenuAction property var menuAction: videoInputMenuAction
enabled: CurrentAccount.videoEnabled_Video
onEnabledChanged: CallOverlayModel.setEnabled(this, muteVideoAction.enabled)
} }
] ]
...@@ -319,6 +322,8 @@ Control { ...@@ -319,6 +322,8 @@ Control {
icon.source: JamiResources.add_people_black_24dp_svg icon.source: JamiResources.add_people_black_24dp_svg
icon.color: "white" icon.color: "white"
text: JamiStrings.addParticipants text: JamiStrings.addParticipants
enabled: CurrentCall.isModerator && !CurrentCall.isSIP
onEnabledChanged: CallOverlayModel.setEnabled(this, addPersonAction.enabled)
}, },
Action { Action {
id: chatAction id: chatAction
...@@ -333,6 +338,8 @@ Control { ...@@ -333,6 +338,8 @@ Control {
icon.source: CurrentCall.isPaused ? JamiResources.play_circle_outline_24dp_svg : JamiResources.pause_circle_outline_24dp_svg icon.source: CurrentCall.isPaused ? JamiResources.play_circle_outline_24dp_svg : JamiResources.pause_circle_outline_24dp_svg
icon.color: "white" icon.color: "white"
text: CurrentCall.isPaused ? JamiStrings.resumeCall : JamiStrings.pauseCall text: CurrentCall.isPaused ? JamiStrings.resumeCall : JamiStrings.pauseCall
enabled: CurrentCall.isSIP
onEnabledChanged: CallOverlayModel.setEnabled(this, resumePauseCallAction.enabled)
}, },
Action { Action {
id: inputPanelSIPAction id: inputPanelSIPAction
...@@ -340,6 +347,8 @@ Control { ...@@ -340,6 +347,8 @@ Control {
icon.source: JamiResources.ic_keypad_svg icon.source: JamiResources.ic_keypad_svg
icon.color: "white" icon.color: "white"
text: JamiStrings.sipInputPanel text: JamiStrings.sipInputPanel
enabled: CurrentCall.isSIP
onEnabledChanged: CallOverlayModel.setEnabled(this, inputPanelSIPAction.enabled)
}, },
Action { Action {
id: callTransferAction id: callTransferAction
...@@ -347,6 +356,8 @@ Control { ...@@ -347,6 +356,8 @@ Control {
icon.source: JamiResources.phone_forwarded_24dp_svg icon.source: JamiResources.phone_forwarded_24dp_svg
icon.color: "white" icon.color: "white"
text: JamiStrings.transferCall text: JamiStrings.transferCall
enabled: CurrentCall.isSIP
onEnabledChanged: CallOverlayModel.setEnabled(this, callTransferAction.enabled)
}, },
Action { Action {
id: shareAction id: shareAction
...@@ -361,6 +372,8 @@ Control { ...@@ -361,6 +372,8 @@ Control {
text: CurrentCall.isSharing ? JamiStrings.stopSharing : JamiStrings.shareScreen text: CurrentCall.isSharing ? JamiStrings.stopSharing : JamiStrings.shareScreen
property real size: 34 property real size: 34
property var menuAction: shareMenuAction property var menuAction: shareMenuAction
enabled: CurrentAccount.videoEnabled_Video && !CurrentCall.isSIP
onEnabledChanged: CallOverlayModel.setEnabled(this, shareAction.enabled)
}, },
Action { Action {
id: raiseHandAction id: raiseHandAction
...@@ -371,6 +384,8 @@ Control { ...@@ -371,6 +384,8 @@ Control {
text: checked ? JamiStrings.lowerHand : JamiStrings.raiseHand text: checked ? JamiStrings.lowerHand : JamiStrings.raiseHand
checked: CurrentCall.isHandRaised checked: CurrentCall.isHandRaised
property real size: 34 property real size: 34
enabled: CurrentCall.isConference
onEnabledChanged: CallOverlayModel.setEnabled(this, raiseHandAction.enabled)
}, },
Action { Action {
id: layoutAction id: layoutAction
...@@ -406,6 +421,7 @@ Control { ...@@ -406,6 +421,7 @@ Control {
icon.color: "white" icon.color: "white"
text: JamiStrings.viewPlugin text: JamiStrings.viewPlugin
enabled: PluginAdapter.isEnabled && PluginAdapter.callMediaHandlersListCount enabled: PluginAdapter.isEnabled && PluginAdapter.callMediaHandlersListCount
onEnabledChanged: CallOverlayModel.setEnabled(this, pluginsAction.enabled)
}, },
Action { Action {
id: swarmDetailsAction id: swarmDetailsAction
...@@ -414,7 +430,7 @@ Control { ...@@ -414,7 +430,7 @@ Control {
icon.color: "white" icon.color: "white"
text: JamiStrings.details text: JamiStrings.details
enabled: { enabled: {
if (LRCInstance.currentAccountType === Profile.Type.SIP) if (CurrentCall.isSIP)
return true; return true;
if (!CurrentConversation.isTemporary && !CurrentConversation.isSwarm) if (!CurrentConversation.isTemporary && !CurrentConversation.isSwarm)
return false; return false;
...@@ -422,81 +438,35 @@ Control { ...@@ -422,81 +438,35 @@ Control {
return false; return false;
return true; return true;
} }
onEnabledChanged: CallOverlayModel.setEnabled(this, swarmDetailsAction.enabled)
} }
] ]
property var overflowItemCount property var overflowItemCount
Connections { Component.onCompleted: {
target: CurrentCall
function onIsActiveChanged() {
if (CurrentCall.isActive)
reset();
}
function onIsRecordingLocallyChanged() {
Qt.callLater(reset);
}
function onIsHandRaisedChanged() {
Qt.callLater(reset);
}
function onIsConferenceChanged() {
Qt.callLater(reset);
}
function onIsModeratorChanged() {
Qt.callLater(reset);
}
function onIsSIPChanged() {
Qt.callLater(reset);
}
function onIsAudioOnlyChanged() {
Qt.callLater(reset);
}
function onIsAudioMutedChanged() {
Qt.callLater(reset);
}
function onIsVideoMutedChanged() {
Qt.callLater(reset);
}
}
Connections {
target: CurrentAccount
function onVideoEnabledVideoChanged() {
reset();
}
}
function reset() {
CallOverlayModel.clearControls(); CallOverlayModel.clearControls();
// centered controls // centered controls
CallOverlayModel.addPrimaryControl(muteAudioAction); CallOverlayModel.addPrimaryControl(muteAudioAction, muteAudioAction.enabled);
CallOverlayModel.addPrimaryControl(hangupAction); CallOverlayModel.addPrimaryControl(hangupAction, hangupAction.enabled);
if (CurrentAccount.videoEnabled_Video) CallOverlayModel.addPrimaryControl(muteVideoAction, muteVideoAction.enabled);
CallOverlayModel.addPrimaryControl(muteVideoAction);
// overflow controls // overflow controls
CallOverlayModel.addSecondaryControl(audioOutputAction); CallOverlayModel.addSecondaryControl(audioOutputAction, audioOutputAction.enabled);
if (CurrentCall.isConference) { CallOverlayModel.addSecondaryControl(raiseHandAction, raiseHandAction.enabled);
CallOverlayModel.addSecondaryControl(raiseHandAction); CallOverlayModel.addSecondaryControl(addPersonAction, addPersonAction.enabled);
}
if (CurrentCall.isModerator && !CurrentCall.isSIP) CallOverlayModel.addSecondaryControl(resumePauseCallAction, resumePauseCallAction.enabled);
CallOverlayModel.addSecondaryControl(addPersonAction); CallOverlayModel.addSecondaryControl(inputPanelSIPAction, inputPanelSIPAction.enabled);
if (CurrentCall.isSIP) { CallOverlayModel.addSecondaryControl(callTransferAction, callTransferAction.enabled);
CallOverlayModel.addSecondaryControl(resumePauseCallAction);
CallOverlayModel.addSecondaryControl(inputPanelSIPAction); CallOverlayModel.addSecondaryControl(chatAction, chatAction.enabled);
CallOverlayModel.addSecondaryControl(callTransferAction); CallOverlayModel.addSecondaryControl(shareAction, shareAction.enabled);
} CallOverlayModel.addSecondaryControl(layoutAction, layoutAction.enabled);
CallOverlayModel.addSecondaryControl(chatAction); CallOverlayModel.addSecondaryControl(recordAction, recordAction.enabled);
if (CurrentAccount.videoEnabled_Video && !CurrentCall.isSIP) CallOverlayModel.addSecondaryControl(pluginsAction, pluginsAction.enabled);
CallOverlayModel.addSecondaryControl(shareAction); CallOverlayModel.addSecondaryControl(swarmDetailsAction, swarmDetailsAction.enabled);
CallOverlayModel.addSecondaryControl(layoutAction);
CallOverlayModel.addSecondaryControl(recordAction);
if (pluginsAction.enabled)
CallOverlayModel.addSecondaryControl(pluginsAction);
if (swarmDetailsAction.enabled)
CallOverlayModel.addSecondaryControl(swarmDetailsAction);
overflowItemCount = CallOverlayModel.secondaryModel().rowCount(); overflowItemCount = CallOverlayModel.secondaryModel().rowCount();
} }
...@@ -519,7 +489,13 @@ Control { ...@@ -519,7 +489,13 @@ Control {
implicitHeight: contentHeight implicitHeight: contentHeight
interactive: false interactive: false
model: CallOverlayModel.primaryModel() model: SortFilterProxyModel {
sourceModel: CallOverlayModel.primaryModel()
filters: ValueFilter {
roleName: "Enabled"
value: true
}
}
delegate: buttonDelegate delegate: buttonDelegate
} }
} }
...@@ -547,7 +523,15 @@ Control { ...@@ -547,7 +523,15 @@ Control {
property int overflowIndex: { property int overflowIndex: {
var maxItems = Math.floor((overflowRect.remainingSpace) / (root.height + itemSpacing)) - 2; var maxItems = Math.floor((overflowRect.remainingSpace) / (root.height + itemSpacing)) - 2;
return Math.min(overflowItemCount, maxItems); var idx = Math.min(overflowItemCount, maxItems);
idx = Math.max(0, idx);
if (CallOverlayModel.overflowModel().rowCount() > 0 || CallOverlayModel.overflowHiddenModel().rowCount() > 0) {
var visibleIdx = CallOverlayModel.overflowModel().mapToSource(CallOverlayModel.overflowModel().index(idx, 0)).row;
var hiddenIdx = CallOverlayModel.overflowHiddenModel().mapToSource(CallOverlayModel.overflowHiddenModel().index(idx - CallOverlayModel.overflowModel().rowCount(), 0)).row;
if (visibleIdx >= 0 || hiddenIdx >= 0)
idx = Math.max(visibleIdx, hiddenIdx);
}
return idx;
} }
property int nOverflowItems: overflowItemCount - overflowIndex property int nOverflowItems: overflowItemCount - overflowIndex
onNOverflowItemsChanged: { onNOverflowItemsChanged: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment