Commit f3567cc4 authored by Ming Rui Zhang's avatar Ming Rui Zhang

currentaccountcombox: add voicemail notification functionality

Change-Id: Ic49960677691f6e5a60a941ef3c81121e03e6886
parent 6578a311
......@@ -1122,6 +1122,7 @@ CallWidget::connectConversationModel()
updateSmartList();
updateConversationForNewContact(convUid);
ui->conversationsFilterWidget->update();
ui->currentAccountComboBox->canPlaceAudioOnlyCall(convUid);
}
);
conversationRemovedConnection_ = QObject::connect(
......
......@@ -19,9 +19,6 @@
#include "currentaccountcombobox.h"
#include <QPixmap>
#include <QMouseEvent>
#include "accountitemdelegate.h"
#include "pixbufmanipulator.h"
#include "utils.h"
......@@ -29,6 +26,10 @@
#include "lrcinstance.h"
#include "mainwindow.h"
#include <QPixmap>
#include <QMessageBox>
#include <QMouseEvent>
#undef REGISTERED
CurrentAccountComboBox::CurrentAccountComboBox(QWidget* parent)
......@@ -37,6 +38,9 @@ CurrentAccountComboBox::CurrentAccountComboBox(QWidget* parent)
setMouseTracking(true);
gearLabel_.setMouseTracking(true);
voicemailButton_.setMouseTracking(true);
voicemailButton_.setNeedToShowNotify(false);
voicemailButton_.setEnabled(false);
accountListUpdate();
accountItemDelegate_ = new AccountItemDelegate(this);
......@@ -59,10 +63,65 @@ CurrentAccountComboBox::CurrentAccountComboBox(QWidget* parent)
}
});
// voicemail received
connect(LRCInstance::getCurrentCallModel(), &lrc::api::NewCallModel::voiceMailNotify,
[this] (const std::string& accountId, int newCount, int oldCount, int urgentCount) {
Q_UNUSED(urgentCount);
voicemailMap_[accountId] = std::make_pair(newCount, oldCount);
if (LRCInstance::accountModel().getAccountList()[currentIndex()] == accountId) {
if (newCount == 0 && oldCount == 0) {
voicemailButton_.setNeedToShowNotify(false);
voicemailButton_.setEnabled(false);
return;
}
if (newCount == 0) {
voicemailButton_.setNotifyNumber(oldCount);
voicemailButton_.setGreyStyleNotification(true);
} else {
voicemailButton_.setNotifyNumber(newCount);
voicemailButton_.setGreyStyleNotification(false);
}
voicemailButton_.setNeedToShowNotify(true);
voicemailButton_.setEnabled(true);
}
});
connect(&voicemailButton_, &QAbstractButton::clicked,
[this] {
auto currentAccountId = LRCInstance::accountModel().getAccountList()[currentIndex()];
auto &accInfo = LRCInstance::accountModel().getAccountInfo(currentAccountId);
auto conversationModel = accInfo.conversationModel.get();
auto confProps = LRCInstance::accountModel().getAccountConfig(currentAccountId);
auto possibleConv = LRCInstance::getConversationFromPeerUri(confProps.mailbox);
if (possibleConv.uid.empty()) {
if (confProps.mailbox.empty()) {
QMessageBox::information(0, "Voicemail", "Voicemail dial code is empty");
}
// construct new contact
lrc::api::profile::Type type{ lrc::api::profile::Type::SIP };
lrc::api::contact::Info contactInfo{ {{confProps.mailbox}, {} , {"Voicemail"}, type }, {} };
Utils::oneShotConnect(this, &CurrentAccountComboBox::placeAudioOnlyCall,
[this, conversationModel] (const std::string& convUid) {
conversationModel->placeAudioOnlyCall(convUid);
});
accInfo.contactModel->addContact(contactInfo);
} else {
// contact existed
conversationModel->placeAudioOnlyCall(possibleConv.uid);
}
});
gearLabel_.setPixmap(QPixmap(":/images/icons/round-settings-24px.svg"));
gearLabel_.setParent(this);
gearLabel_.setStyleSheet("background: transparent;");
setupSettingsButton();
voicemailButton_.setIcon(QIcon(QPixmap(":/images/icons/ic_voicemail_black_24dp_2x_.png")));
voicemailButton_.setParent(this);
voicemailButton_.setStyleSheet("background: transparent;");
setupVoicemailButton();
}
CurrentAccountComboBox::~CurrentAccountComboBox()
......@@ -126,12 +185,12 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e)
painter.setFont(fontPrimary);
painter.setPen(RingTheme::lightBlack_);
primaryAccountID = fontMetricPrimary.elidedText(primaryAccountID, Qt::ElideRight,
comboBoxRect.width() - elidConst - (popupPresent ? 0 : 2 * gearSize_));
comboBoxRect.width() - elidConst - (popupPresent ? 0 : 2 * gearSize_ + 2 * voicemailSize_));
painter.drawText(comboBoxRect, Qt::AlignLeft, primaryAccountID);
QString secondaryAccountID = QString::fromStdString(Utils::secondBestNameForAccount(LRCInstance::getCurrentAccountInfo()));
secondaryAccountID = fontMetricSecondary.elidedText(secondaryAccountID, Qt::ElideRight,
comboBoxRect.width() - elidConst - 2 - (popupPresent ? 0 : 2 * gearSize_)); // [screen awareness]
comboBoxRect.width() - elidConst - 2 - (popupPresent ? 0 : 2 * gearSize_ + 2 * voicemailSize_)); // [screen awareness]
if (secondaryAccountID.length()) { // if secondary accound id exists
painter.setFont(fontSecondary);
......@@ -148,6 +207,7 @@ void CurrentAccountComboBox::resizeEvent(QResizeEvent* event)
{
Q_UNUSED(event);
setupSettingsButton();
setupVoicemailButton();
}
void
......@@ -162,6 +222,17 @@ CurrentAccountComboBox::setupSettingsButton()
gearLabel_.setMargin(gearBorder_);
}
void
CurrentAccountComboBox::setupVoicemailButton()
{
voicemailPoint_.setX(this->width() - gearSize_ - voicemailSize_ - 6 * voicemailBorder_ - 5 * gearBorder_ - 1);
voicemailPoint_.setY(this->height() / 2 - voicemailButton_.height() / 2 - 2 * voicemailBorder_ + 8);
voicemailButton_.setGeometry(
voicemailPoint_.x(), voicemailPoint_.y(),
voicemailSize_ + 2 * voicemailBorder_,
voicemailSize_ + 2 * voicemailBorder_);
}
// import account background account pixmap and scale pixmap to fit in label
void
CurrentAccountComboBox::importLabelPhoto(int index)
......@@ -177,11 +248,42 @@ void
CurrentAccountComboBox::setCurrentIndex(int index)
{
auto accountListSize = LRCInstance::accountModel().getAccountList().size();
if (index == accountListSize) {
emit newAccountClicked();
} else if (index < accountListSize) {
importLabelPhoto(index);
QComboBox::setCurrentIndex(index);
auto accountId = LRCInstance::accountModel().getAccountList()[index];
auto& info = LRCInstance::accountModel().getAccountInfo(accountId);
if (!(info.profileInfo.type == lrc::api::profile::Type::SIP)) {
voicemailButton_.setNeedToShowNotify(false);
voicemailButton_.setEnabled(false);
} else {
if (voicemailMap_.find(accountId) != voicemailMap_.end()) {
int newVoiceMail = voicemailMap_[accountId].first;
int oldVoiceMail = voicemailMap_[accountId].second;
if (newVoiceMail == 0 && oldVoiceMail == 0) {
voicemailButton_.setNeedToShowNotify(false);
voicemailButton_.setEnabled(false);
return;
}
if (newVoiceMail == 0) {
voicemailButton_.setNotifyNumber(oldVoiceMail);
voicemailButton_.setGreyStyleNotification(true);
} else {
voicemailButton_.setNotifyNumber(newVoiceMail);
voicemailButton_.setGreyStyleNotification(false);
}
voicemailButton_.setNeedToShowNotify(true);
voicemailButton_.setEnabled(true);
return;
}
voicemailButton_.setNeedToShowNotify(false);
voicemailButton_.setEnabled(false);
}
}
}
......@@ -196,10 +298,10 @@ CurrentAccountComboBox::accountListUpdate()
void
CurrentAccountComboBox::mousePressEvent(QMouseEvent* mouseEvent)
{
if (!gearLabel_.frameGeometry().contains(mouseEvent->localPos().toPoint())) {
QComboBox::mousePressEvent(mouseEvent);
} else {
if (gearLabel_.frameGeometry().contains(mouseEvent->localPos().toPoint())) {
emit settingsButtonClicked();
} else {
QComboBox::mousePressEvent(mouseEvent);
}
}
......@@ -211,14 +313,21 @@ CurrentAccountComboBox::mouseMoveEvent(QMouseEvent* mouseEvent)
QComboBox::mouseMoveEvent(mouseEvent);
gearLabel_.setStyleSheet("background: rgb(237, 237, 237); border-width: 0px; border-radius: 15px;");
return;
} else if (voicemailButton_.geometry().contains(mouseEvent->localPos().toPoint())) {
QComboBox::mouseMoveEvent(mouseEvent);
voicemailButton_.setStyleSheet("background: rgb(237, 237, 237); border-width: 0px; border-radius: 15px;");
return;
}
voicemailButton_.setStyleSheet("background: transparent;");
gearLabel_.setStyleSheet("background: transparent;");
}
void
CurrentAccountComboBox::showPopup()
{
voicemailButton_.setNeedToShowNotify(false);
voicemailButton_.setEnabled(false);
gearLabel_.hide();
popupPresent = true;
QComboBox::showPopup();
......@@ -227,6 +336,13 @@ CurrentAccountComboBox::showPopup()
void
CurrentAccountComboBox::hidePopup()
{
auto accountId { LRCInstance::getCurrAccId() };
auto& info = LRCInstance::accountModel().getAccountInfo(accountId);
if (info.profileInfo.type == lrc::api::profile::Type::SIP
&& voicemailMap_.find(accountId) != voicemailMap_.end()) {
voicemailButton_.setNeedToShowNotify(true);
voicemailButton_.setEnabled(true);
}
gearLabel_.show();
popupPresent = false;
QComboBox::hidePopup();
......@@ -235,6 +351,7 @@ CurrentAccountComboBox::hidePopup()
void
CurrentAccountComboBox::leaveEvent(QEvent* event)
{
voicemailButton_.setStyleSheet("background: transparent;");
gearLabel_.setStyleSheet("background: transparent;");
QComboBox::leaveEvent(event);
}
......
......@@ -16,11 +16,16 @@
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#pragma once
#include <QComboBox>
#include <QLabel>
#include "accountlistmodel.h"
#include "accountitemdelegate.h"
#include "notifypushbutton.h"
#include <QComboBox>
#include <QLabel>
#include <QPushButton>
namespace Ui {
class CurrentAccountComboBox;
......@@ -37,10 +42,12 @@ public:
void accountListUpdate();
void setCurrentIndex(int index);
void updateComboBoxDisplay();
void canPlaceAudioOnlyCall(const std::string& convUid) { emit placeAudioOnlyCall(convUid); }
signals:
void settingsButtonClicked();
void newAccountClicked();
void placeAudioOnlyCall(const std::string& convUid);
protected:
void paintEvent(QPaintEvent* e);
......@@ -54,6 +61,7 @@ protected:
private:
void importLabelPhoto(int index);
void setupSettingsButton();
void setupVoicemailButton();
AccountItemDelegate* accountItemDelegate_;
std::unique_ptr<AccountListModel> accountListModel_;
......@@ -68,4 +76,11 @@ private:
QPoint gearPoint_;
QLabel gearLabel_;
QPoint voicemailPoint_;
NotifyPushButton voicemailButton_;
const int voicemailBorder_ = 4;
const int voicemailSize_ = 24;
std::map<std::string,std::pair<int,int>> voicemailMap_;
};
......@@ -78,7 +78,8 @@ HEADERS += ./aboutdialog.h \
./previewwidget.h \
./rendermanager.h \
./distantwidget.h \
./videowidgetbase.h
./videowidgetbase.h \
./notifypushbutton.h
SOURCES += ./aboutdialog.cpp \
./banneditemwidget.cpp \
./conversationsfilterwidget.cpp \
......@@ -138,7 +139,8 @@ SOURCES += ./aboutdialog.cpp \
./previewwidget.cpp \
./rendermanager.cpp \
./distantwidget.cpp \
./videowidgetbase.cpp
./videowidgetbase.cpp \
./notifypushbutton.cpp
FORMS += ./aboutdialog.ui \
./advancedsipsettingwidget.ui \
./callwidget.ui \
......
/**************************************************************************
* Copyright (C) 2019 by Savoir-faire Linux *
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "notifypushbutton.h"
#include "lrcinstance.h"
#include <QPainter>
#include <QPainterPath>
NotifyPushButton::NotifyPushButton(QWidget* parent,
// count
int newCount,
int notifyLimit,
// geo
int circleRadiusDivideRatio,
int circleRadiusMakeup,
int notifyCirclePresenceMakeup,
int notifyTextCorrectionY,
int notifyTextCorrectionX,
int notifyTextCorrectionXOverLimit,
// font size
int notifyNumberFontSize,
int notifyNumberFontSizeDeductionOverLimit) :
QPushButton(parent),
newCount_(newCount),
notifyLimit_(notifyLimit),
circleRadiusDivideRatio_(circleRadiusDivideRatio),
circleRadiusMakeup_(circleRadiusMakeup),
notifyCirclePresenceMakeup_(notifyCirclePresenceMakeup),
notifyTextCorrectionY_(notifyTextCorrectionY),
notifyTextCorrectionX_(notifyTextCorrectionX),
notifyTextCorrectionXOverLimit_(notifyTextCorrectionXOverLimit),
notifyNumberFontSize_(notifyNumberFontSize),
notifyNumberFontSizeDeductionOverLimit_(notifyNumberFontSizeDeductionOverLimit)
{
}
NotifyPushButton::~NotifyPushButton()
{
}
void
NotifyPushButton::paintEvent(QPaintEvent* e)
{
if (!needToNotify_) {
setEnabled(false);
return;
}
QPushButton::paintEvent(e);
// set up
bool isOverNotifyLimit = (newCount_ > notifyLimit_) ? true : false;
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
QFont font;
font.setPixelSize(isOverNotifyLimit ? notifyNumberFontSize_ - notifyNumberFontSizeDeductionOverLimit_ : notifyNumberFontSize_);
font.setWeight(QFont::Bold);
QPainterPath notifyCircle;
QPointF presenceCenter(height() - notifyCirclePresenceMakeup_, height() - notifyCirclePresenceMakeup_);
qreal circleRadius = height() / circleRadiusDivideRatio_ + circleRadiusMakeup_;
// draw circle
notifyCircle.addEllipse(presenceCenter, circleRadius, circleRadius);
painter.fillPath(notifyCircle, greyStyleNotification_ ? QBrush(QColor("grey")) : QBrush(QColor("red")));
// draw notify count
presenceCenter.setY(height() - notifyTextCorrectionY_);
presenceCenter.setX(isOverNotifyLimit ?
height() - notifyTextCorrectionX_ - notifyTextCorrectionXOverLimit_:
height() - notifyTextCorrectionX_);
painter.setPen(QPen(QColor("white")));
painter.setOpacity(1);
painter.setFont(font);
QString notifyCount = (isOverNotifyLimit) ? (QString::number(notifyLimit_) + "+") : QString::number(newCount_);
painter.drawText(presenceCenter, notifyCount);
}
/**************************************************************************
* Copyright (C) 2019 by Savoir-faire Linux *
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#pragma once
#include "utils.h"
#include <QColor>
#include <QImage>
#include <QPaintEvent>
#include <QPushButton>
class NotifyPushButton : public QPushButton {
Q_OBJECT
public:
// note that height should always be equal to the width for this button
explicit NotifyPushButton(QWidget* parent = nullptr,
// count
int newCount = 0,
int notifyLimit = 9,
// geo
int circleRadiusDivideRatio = 5,
int circleRadiusMakeup = 0 ,
int notifyCirclePresenceMakeup = 8,
int notifyTextCorrectionY = 5,
int notifyTextCorrectionX = 11,
int notifyTextCorrectionXOverLimit = 2,
// font size
int notifyNumberFontSize = 10,
int notifyNumberFontSizeDeductionOverLimit = 2);
~NotifyPushButton();
// count
void setNotifyNumber(int num) { newCount_ = num; }
int getNotifyNumber() { return newCount_; }
void setNotifyLimit(int limit) { notifyLimit_ = limit; }
void setNeedToShowNotify(bool need) { needToNotify_ = need; }
void setGreyStyleNotification(bool grey) { greyStyleNotification_ = grey; }
protected:
void paintEvent(QPaintEvent* e);
private:
// count
int newCount_;
int notifyLimit_;
// geo
int circleRadiusDivideRatio_;
int circleRadiusMakeup_;
int notifyCirclePresenceMakeup_;
int notifyTextCorrectionY_;
int notifyTextCorrectionX_;
int notifyTextCorrectionXOverLimit_;
// font size
int notifyNumberFontSize_;
int notifyNumberFontSizeDeductionOverLimit_;
bool needToNotify_ { true };
bool greyStyleNotification_ { false };
};
......@@ -88,5 +88,6 @@
<file>images/icons/icon-keypad-24.png</file>
<file>images/icons/ic_play_white_24dp.png</file>
<file>images/icons/icon-keypad-24-2x.png</file>
<file>images/icons/ic_voicemail_black_24dp_2x_.png</file>
</qresource>
</RCC>
\ No newline at end of file
......@@ -351,6 +351,7 @@ del /s /q $(OutDir)\Jami.exp</Command>
<ClCompile Include="aboutdialog.cpp" />
<ClCompile Include="distantwidget.cpp" />
<ClCompile Include="levelmeter.cpp" />
<ClCompile Include="notifypushbutton.cpp" />
<ClCompile Include="overlaybutton.cpp" />
<ClCompile Include="previewwidget.cpp" />
<ClCompile Include="rendermanager.cpp" />
......@@ -644,6 +645,10 @@ del /s /q $(OutDir)\Jami.exp</Command>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='ReleaseCompile|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)winsparkle\include;$(ProjectDir)qrencode-win32\qrencode-win32;$(QTDIR)\include;$(QTDIR)\include\QtSvg;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtWinExtras;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtXml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Beta|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)qrencode-win32\qrencode-win32;$(QTDIR)\include;$(QTDIR)\include\QtSvg;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtWinExtras;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtXml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
</QtMoc>
<QtMoc Include="notifypushbutton.h">
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)qrencode-win32\qrencode-win32;$(QTDIR)\include;$(QTDIR)\include\QtSvg;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtWinExtras;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtXml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='ReleaseCompile|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)winsparkle\include;$(ProjectDir)qrencode-win32\qrencode-win32;$(QTDIR)\include;$(QTDIR)\include\QtSvg;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtWinExtras;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtXml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
</QtMoc>
<ClInclude Include="pixbufmanipulator.h" />
<QtMoc Include="ringbutton.h">
</QtMoc>
......
......@@ -243,6 +243,9 @@
<ClCompile Include="distantwidget.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="notifypushbutton.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="aboutdialog.h">
......@@ -428,6 +431,9 @@
<QtMoc Include="distantwidget.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="notifypushbutton.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment