Fixed MWI icon if no count is provided in the NOTIFY (only yes/no)

This commit is contained in:
Christophe Deschamps 2024-11-02 19:14:31 +01:00
parent b6284ea1e6
commit 78f5656482
7 changed files with 34 additions and 5 deletions

View file

@ -97,6 +97,7 @@ AccountCore::AccountCore(const std::shared_ptr<linphone::Account> &account) : QO
}
INIT_CORE_MEMBER(VoicemailCount, mAccountModel)
INIT_CORE_MEMBER(ShowMwi, mAccountModel)
}
AccountCore::~AccountCore() {
@ -268,6 +269,7 @@ void AccountCore::setSelf(QSharedPointer<AccountCore> me) {
DEFINE_CORE_GET_CONNECT(mAccountModelConnection, AccountCore, AccountModel, mAccountModel, int, voicemailCount,
VoicemailCount)
DEFINE_CORE_GET_CONNECT(mAccountModelConnection, AccountCore, AccountModel, mAccountModel, int, showMwi, ShowMwi)
}
const std::shared_ptr<AccountModel> &AccountCore::getModel() const {

View file

@ -72,6 +72,7 @@ class AccountCore : public QObject, public AbstractObject {
lSetAudioVideoConferenceFactoryAddress NOTIFY audioVideoConferenceFactoryAddressChanged)
Q_PROPERTY(QString limeServerUrl READ getLimeServerUrl WRITE lSetLimeServerUrl NOTIFY limeServerUrlChanged)
DECLARE_CORE_GET(int, voicemailCount, VoicemailCount)
DECLARE_CORE_GET(bool, showMwi, ShowMwi)
public:
static QSharedPointer<AccountCore> create(const std::shared_ptr<linphone::Account> &account);

View file

@ -67,8 +67,10 @@ void AccountModel::onMessageWaitingIndicationChanged(
auto userData = getUserData(account);
if (!userData) userData = std::make_shared<AccountUserData>();
userData->voicemailCount = summary->getNbNew();
userData->showMwi = mwi->hasMessageWaiting();
setUserData(account, userData);
emit voicemailCountChanged(summary->getNbNew());
emit showMwiChanged(mwi->hasMessageWaiting());
}
}
@ -311,6 +313,12 @@ int AccountModel::getVoicemailCount() {
else return 0;
}
bool AccountModel::getShowMwi() {
auto userData = getUserData(mMonitor);
if (userData) return userData->showMwi;
else return false;
}
// UserData (see hpp for explanations)
static QMap<const std::shared_ptr<linphone::Account>, std::shared_ptr<AccountUserData>> userDataMap;

View file

@ -67,6 +67,7 @@ public:
void setLimeServerUrl(QString value);
QString dialPlanAsString(const std::shared_ptr<linphone::DialPlan> &dialPlan);
int getVoicemailCount();
bool getShowMwi();
signals:
void registrationStateChanged(const std::shared_ptr<linphone::Account> &account,
@ -94,6 +95,7 @@ signals:
void limeServerUrlChanged(QString value);
void removed();
void voicemailCountChanged(int count);
void showMwiChanged(bool show);
private:
/**Linphone **/
@ -118,6 +120,7 @@ private:
struct AccountUserData {
int voicemailCount;
bool showMwi;
// ..
};

View file

@ -148,6 +148,7 @@ Control.Control{
Layout.rightMargin: 20 * DefaultStyle.dp
Layout.preferredWidth: 27 * DefaultStyle.dp
Layout.preferredHeight: 28 * DefaultStyle.dp
visible: mainItem.account.core.showMwi
voicemailCount: mainItem.account.core.voicemailCount >= 100 ? '99+' : mainItem.account.core.voicemailCount
onClicked: {
if (mainItem.account.core.mwiServerAddress.length > 0)

View file

@ -9,7 +9,6 @@ import SettingsCpp
Rectangle{
id: mainItem
property int voicemailCount: 0
visible: voicemailCount > 0
width: 27 * DefaultStyle.dp
height: 28 * DefaultStyle.dp
signal clicked()

View file

@ -398,14 +398,29 @@ Item {
Layout.preferredWidth: 27 * DefaultStyle.dp
Layout.preferredHeight: 28 * DefaultStyle.dp
function cumulatedVoicemailCount() {
Repeater {
model: accountProxy
Connections {
target: modelData.core
onMwiChanged: updateCumulatedMwi()
}
}
function updateCumulatedMwi() {
var count = 0
for (var i=0 ; i < accountProxy.count ; i++ )
var show = false
for (var i=0 ; i < accountProxy.count ; i++ ) {
count += accountProxy.getAt(i).core.voicemailCount
return count
show |= accountProxy.getAt(i).core.showMwi
}
voicemail.visible = show
voicemail.voicemailCount = count
}
Component.onCompleted: {
updateCumulatedMwi()
}
voicemailCount: cumulatedVoicemailCount()
onClicked: {
if (accountProxy.count > 1) {
avatarButton.popup.open()