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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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