mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 13:08:48 +03:00
Make incoming call ringtone a user setting
This commit is contained in:
parent
d391404b79
commit
8c037f83c5
4 changed files with 89 additions and 6 deletions
|
@ -98,7 +98,7 @@ CallManager::CallManager(QObject *parent)
|
||||||
connect(&session_, &WebRTCSession::stateChanged, this, [this](webrtc::State state) {
|
connect(&session_, &WebRTCSession::stateChanged, this, [this](webrtc::State state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case webrtc::State::DISCONNECTED:
|
case webrtc::State::DISCONNECTED:
|
||||||
playRingtone("qrc:/media/media/callend.ogg", false);
|
playRingtone(QUrl("qrc:/media/media/callend.ogg"), false);
|
||||||
clear();
|
clear();
|
||||||
break;
|
break;
|
||||||
case webrtc::State::ICEFAILED: {
|
case webrtc::State::ICEFAILED: {
|
||||||
|
@ -121,6 +121,24 @@ CallManager::CallManager(QObject *parent)
|
||||||
if (status == QMediaPlayer::LoadedMedia)
|
if (status == QMediaPlayer::LoadedMedia)
|
||||||
player_.play();
|
player_.play();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(&player_,
|
||||||
|
QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error),
|
||||||
|
[this](QMediaPlayer::Error error) {
|
||||||
|
stopRingtone();
|
||||||
|
switch (error) {
|
||||||
|
case QMediaPlayer::FormatError:
|
||||||
|
case QMediaPlayer::ResourceError:
|
||||||
|
nhlog::ui()->error("WebRTC: valid ringtone file not found");
|
||||||
|
break;
|
||||||
|
case QMediaPlayer::AccessDeniedError:
|
||||||
|
nhlog::ui()->error("WebRTC: access to ringtone file denied");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
nhlog::ui()->error("WebRTC: unable to play ringtone");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -153,7 +171,7 @@ CallManager::sendInvite(const QString &roomid, bool isVideo)
|
||||||
callPartyName_ = callee.display_name.isEmpty() ? callee.user_id : callee.display_name;
|
callPartyName_ = callee.display_name.isEmpty() ? callee.user_id : callee.display_name;
|
||||||
callPartyAvatarUrl_ = QString::fromStdString(roomInfo.avatar_url);
|
callPartyAvatarUrl_ = QString::fromStdString(roomInfo.avatar_url);
|
||||||
emit newCallParty();
|
emit newCallParty();
|
||||||
playRingtone("qrc:/media/media/ringback.ogg", true);
|
playRingtone(QUrl("qrc:/media/media/ringback.ogg"), true);
|
||||||
if (!session_.createOffer(isVideo)) {
|
if (!session_.createOffer(isVideo)) {
|
||||||
emit ChatPage::instance()->showNotification("Problem setting up call.");
|
emit ChatPage::instance()->showNotification("Problem setting up call.");
|
||||||
endCall();
|
endCall();
|
||||||
|
@ -247,7 +265,11 @@ CallManager::handleEvent(const RoomEvent<CallInvite> &callInviteEvent)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
playRingtone("qrc:/media/media/ring.ogg", true);
|
const QString &ringtone = ChatPage::instance()->userSettings()->ringtone();
|
||||||
|
if (ringtone != "Mute")
|
||||||
|
playRingtone(ringtone == "Default" ? QUrl("qrc:/media/media/ring.ogg")
|
||||||
|
: QUrl::fromLocalFile(ringtone),
|
||||||
|
true);
|
||||||
roomid_ = QString::fromStdString(callInviteEvent.room_id);
|
roomid_ = QString::fromStdString(callInviteEvent.room_id);
|
||||||
callid_ = callInviteEvent.content.call_id;
|
callid_ = callInviteEvent.content.call_id;
|
||||||
remoteICECandidates_.clear();
|
remoteICECandidates_.clear();
|
||||||
|
@ -409,13 +431,13 @@ CallManager::retrieveTurnServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CallManager::playRingtone(const QString &ringtone, bool repeat)
|
CallManager::playRingtone(const QUrl &ringtone, bool repeat)
|
||||||
{
|
{
|
||||||
static QMediaPlaylist playlist;
|
static QMediaPlaylist playlist;
|
||||||
playlist.clear();
|
playlist.clear();
|
||||||
playlist.setPlaybackMode(repeat ? QMediaPlaylist::CurrentItemInLoop
|
playlist.setPlaybackMode(repeat ? QMediaPlaylist::CurrentItemInLoop
|
||||||
: QMediaPlaylist::CurrentItemOnce);
|
: QMediaPlaylist::CurrentItemOnce);
|
||||||
playlist.addMedia(QUrl(ringtone));
|
playlist.addMedia(ringtone);
|
||||||
player_.setVolume(100);
|
player_.setVolume(100);
|
||||||
player_.setPlaylist(&playlist);
|
player_.setPlaylist(&playlist);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace mtx::responses {
|
||||||
struct TurnServer;
|
struct TurnServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class QUrl;
|
||||||
class WebRTCSession;
|
class WebRTCSession;
|
||||||
|
|
||||||
class CallManager : public QObject
|
class CallManager : public QObject
|
||||||
|
@ -69,6 +70,6 @@ private:
|
||||||
void generateCallID();
|
void generateCallID();
|
||||||
void clear();
|
void clear();
|
||||||
void endCall();
|
void endCall();
|
||||||
void playRingtone(const QString &ringtone, bool repeat);
|
void playRingtone(const QUrl &ringtone, bool repeat);
|
||||||
void stopRingtone();
|
void stopRingtone();
|
||||||
};
|
};
|
||||||
|
|
|
@ -83,6 +83,7 @@ UserSettings::load()
|
||||||
presence_ =
|
presence_ =
|
||||||
settings.value("user/presence", QVariant::fromValue(Presence::AutomaticPresence))
|
settings.value("user/presence", QVariant::fromValue(Presence::AutomaticPresence))
|
||||||
.value<Presence>();
|
.value<Presence>();
|
||||||
|
ringtone_ = settings.value("user/ringtone", "Default").toString();
|
||||||
microphone_ = settings.value("user/microphone", QString()).toString();
|
microphone_ = settings.value("user/microphone", QString()).toString();
|
||||||
camera_ = settings.value("user/camera", QString()).toString();
|
camera_ = settings.value("user/camera", QString()).toString();
|
||||||
cameraResolution_ = settings.value("user/camera_resolution", QString()).toString();
|
cameraResolution_ = settings.value("user/camera_resolution", QString()).toString();
|
||||||
|
@ -321,6 +322,16 @@ UserSettings::setShareKeysWithTrustedUsers(bool shareKeys)
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserSettings::setRingtone(QString ringtone)
|
||||||
|
{
|
||||||
|
if (ringtone == ringtone_)
|
||||||
|
return;
|
||||||
|
ringtone_ = ringtone;
|
||||||
|
emit ringtoneChanged(ringtone);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UserSettings::setMicrophone(QString microphone)
|
UserSettings::setMicrophone(QString microphone)
|
||||||
{
|
{
|
||||||
|
@ -450,6 +461,7 @@ UserSettings::save()
|
||||||
settings.setValue("font_family", font_);
|
settings.setValue("font_family", font_);
|
||||||
settings.setValue("emoji_font_family", emojiFont_);
|
settings.setValue("emoji_font_family", emojiFont_);
|
||||||
settings.setValue("presence", QVariant::fromValue(presence_));
|
settings.setValue("presence", QVariant::fromValue(presence_));
|
||||||
|
settings.setValue("ringtone", ringtone_);
|
||||||
settings.setValue("microphone", microphone_);
|
settings.setValue("microphone", microphone_);
|
||||||
settings.setValue("camera", camera_);
|
settings.setValue("camera", camera_);
|
||||||
settings.setValue("camera_resolution", cameraResolution_);
|
settings.setValue("camera_resolution", cameraResolution_);
|
||||||
|
@ -530,6 +542,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
fontSizeCombo_ = new QComboBox{this};
|
fontSizeCombo_ = new QComboBox{this};
|
||||||
fontSelectionCombo_ = new QFontComboBox{this};
|
fontSelectionCombo_ = new QFontComboBox{this};
|
||||||
emojiFontSelectionCombo_ = new QComboBox{this};
|
emojiFontSelectionCombo_ = new QComboBox{this};
|
||||||
|
ringtoneCombo_ = new QComboBox{this};
|
||||||
microphoneCombo_ = new QComboBox{this};
|
microphoneCombo_ = new QComboBox{this};
|
||||||
cameraCombo_ = new QComboBox{this};
|
cameraCombo_ = new QComboBox{this};
|
||||||
cameraResolutionCombo_ = new QComboBox{this};
|
cameraResolutionCombo_ = new QComboBox{this};
|
||||||
|
@ -720,14 +733,26 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
|
|
||||||
formLayout_->addRow(callsLabel);
|
formLayout_->addRow(callsLabel);
|
||||||
formLayout_->addRow(new HorizontalLine{this});
|
formLayout_->addRow(new HorizontalLine{this});
|
||||||
|
boxWrap(tr("Ringtone"),
|
||||||
|
ringtoneCombo_,
|
||||||
|
tr("Set the notification sound to play when a call invite arrives"));
|
||||||
boxWrap(tr("Microphone"), microphoneCombo_);
|
boxWrap(tr("Microphone"), microphoneCombo_);
|
||||||
boxWrap(tr("Camera"), cameraCombo_);
|
boxWrap(tr("Camera"), cameraCombo_);
|
||||||
boxWrap(tr("Camera resolution"), cameraResolutionCombo_);
|
boxWrap(tr("Camera resolution"), cameraResolutionCombo_);
|
||||||
boxWrap(tr("Camera frame rate"), cameraFrameRateCombo_);
|
boxWrap(tr("Camera frame rate"), cameraFrameRateCombo_);
|
||||||
|
|
||||||
|
ringtoneCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
|
ringtoneCombo_->addItem("Mute");
|
||||||
|
ringtoneCombo_->addItem("Default");
|
||||||
|
ringtoneCombo_->addItem("Other...");
|
||||||
|
const QString &ringtone = settings_->ringtone();
|
||||||
|
if (!ringtone.isEmpty() && ringtone != "Mute" && ringtone != "Default")
|
||||||
|
ringtoneCombo_->addItem(ringtone);
|
||||||
microphoneCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
microphoneCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
cameraCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
cameraCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
cameraResolutionCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
cameraResolutionCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
cameraFrameRateCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
cameraFrameRateCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
|
|
||||||
boxWrap(tr("Allow fallback call assist server"),
|
boxWrap(tr("Allow fallback call assist server"),
|
||||||
useStunServer_,
|
useStunServer_,
|
||||||
tr("Will use turn.matrix.org as assist when your home server does not offer one."));
|
tr("Will use turn.matrix.org as assist when your home server does not offer one."));
|
||||||
|
@ -786,6 +811,34 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
||||||
[this](const QString &family) { settings_->setEmojiFontFamily(family.trimmed()); });
|
[this](const QString &family) { settings_->setEmojiFontFamily(family.trimmed()); });
|
||||||
|
|
||||||
|
connect(ringtoneCombo_,
|
||||||
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
||||||
|
[this](const QString &ringtone) {
|
||||||
|
if (ringtone == "Other...") {
|
||||||
|
QString homeFolder =
|
||||||
|
QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
|
||||||
|
auto filepath = QFileDialog::getOpenFileName(
|
||||||
|
this, tr("Select a file"), homeFolder, tr("All Files (*)"));
|
||||||
|
if (!filepath.isEmpty()) {
|
||||||
|
const auto &oldSetting = settings_->ringtone();
|
||||||
|
if (oldSetting != "Mute" && oldSetting != "Default")
|
||||||
|
ringtoneCombo_->removeItem(
|
||||||
|
ringtoneCombo_->findText(oldSetting));
|
||||||
|
settings_->setRingtone(filepath);
|
||||||
|
ringtoneCombo_->addItem(filepath);
|
||||||
|
ringtoneCombo_->setCurrentText(filepath);
|
||||||
|
} else {
|
||||||
|
ringtoneCombo_->setCurrentText(settings_->ringtone());
|
||||||
|
}
|
||||||
|
} else if (ringtone == "Mute" || ringtone == "Default") {
|
||||||
|
const auto &oldSetting = settings_->ringtone();
|
||||||
|
if (oldSetting != "Mute" && oldSetting != "Default")
|
||||||
|
ringtoneCombo_->removeItem(
|
||||||
|
ringtoneCombo_->findText(oldSetting));
|
||||||
|
settings_->setRingtone(ringtone);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
connect(microphoneCombo_,
|
connect(microphoneCombo_,
|
||||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
||||||
[this](const QString µphone) { settings_->setMicrophone(microphone); });
|
[this](const QString µphone) { settings_->setMicrophone(microphone); });
|
||||||
|
@ -916,6 +969,7 @@ UserSettingsPage::showEvent(QShowEvent *)
|
||||||
utils::restoreCombobox(fontSizeCombo_, QString::number(settings_->fontSize()) + " ");
|
utils::restoreCombobox(fontSizeCombo_, QString::number(settings_->fontSize()) + " ");
|
||||||
utils::restoreCombobox(scaleFactorCombo_, QString::number(utils::scaleFactor()));
|
utils::restoreCombobox(scaleFactorCombo_, QString::number(utils::scaleFactor()));
|
||||||
utils::restoreCombobox(themeCombo_, settings_->theme());
|
utils::restoreCombobox(themeCombo_, settings_->theme());
|
||||||
|
utils::restoreCombobox(ringtoneCombo_, settings_->ringtone());
|
||||||
|
|
||||||
// FIXME: Toggle treats true as "off"
|
// FIXME: Toggle treats true as "off"
|
||||||
trayToggle_->setState(!settings_->tray());
|
trayToggle_->setState(!settings_->tray());
|
||||||
|
|
|
@ -73,6 +73,7 @@ class UserSettings : public QObject
|
||||||
Q_PROPERTY(
|
Q_PROPERTY(
|
||||||
QString emojiFont READ emojiFont WRITE setEmojiFontFamily NOTIFY emojiFontChanged)
|
QString emojiFont READ emojiFont WRITE setEmojiFontFamily NOTIFY emojiFontChanged)
|
||||||
Q_PROPERTY(Presence presence READ presence WRITE setPresence NOTIFY presenceChanged)
|
Q_PROPERTY(Presence presence READ presence WRITE setPresence NOTIFY presenceChanged)
|
||||||
|
Q_PROPERTY(QString ringtone READ ringtone WRITE setRingtone NOTIFY ringtoneChanged)
|
||||||
Q_PROPERTY(QString microphone READ microphone WRITE setMicrophone NOTIFY microphoneChanged)
|
Q_PROPERTY(QString microphone READ microphone WRITE setMicrophone NOTIFY microphoneChanged)
|
||||||
Q_PROPERTY(QString camera READ camera WRITE setCamera NOTIFY cameraChanged)
|
Q_PROPERTY(QString camera READ camera WRITE setCamera NOTIFY cameraChanged)
|
||||||
Q_PROPERTY(QString cameraResolution READ cameraResolution WRITE setCameraResolution NOTIFY
|
Q_PROPERTY(QString cameraResolution READ cameraResolution WRITE setCameraResolution NOTIFY
|
||||||
|
@ -120,6 +121,7 @@ public:
|
||||||
void setAvatarCircles(bool state);
|
void setAvatarCircles(bool state);
|
||||||
void setDecryptSidebar(bool state);
|
void setDecryptSidebar(bool state);
|
||||||
void setPresence(Presence state);
|
void setPresence(Presence state);
|
||||||
|
void setRingtone(QString ringtone);
|
||||||
void setMicrophone(QString microphone);
|
void setMicrophone(QString microphone);
|
||||||
void setCamera(QString camera);
|
void setCamera(QString camera);
|
||||||
void setCameraResolution(QString resolution);
|
void setCameraResolution(QString resolution);
|
||||||
|
@ -152,6 +154,7 @@ public:
|
||||||
QString font() const { return font_; }
|
QString font() const { return font_; }
|
||||||
QString emojiFont() const { return emojiFont_; }
|
QString emojiFont() const { return emojiFont_; }
|
||||||
Presence presence() const { return presence_; }
|
Presence presence() const { return presence_; }
|
||||||
|
QString ringtone() const { return ringtone_; }
|
||||||
QString microphone() const { return microphone_; }
|
QString microphone() const { return microphone_; }
|
||||||
QString camera() const { return camera_; }
|
QString camera() const { return camera_; }
|
||||||
QString cameraResolution() const { return cameraResolution_; }
|
QString cameraResolution() const { return cameraResolution_; }
|
||||||
|
@ -181,6 +184,7 @@ signals:
|
||||||
void fontChanged(QString state);
|
void fontChanged(QString state);
|
||||||
void emojiFontChanged(QString state);
|
void emojiFontChanged(QString state);
|
||||||
void presenceChanged(Presence state);
|
void presenceChanged(Presence state);
|
||||||
|
void ringtoneChanged(QString ringtone);
|
||||||
void microphoneChanged(QString microphone);
|
void microphoneChanged(QString microphone);
|
||||||
void cameraChanged(QString camera);
|
void cameraChanged(QString camera);
|
||||||
void cameraResolutionChanged(QString resolution);
|
void cameraResolutionChanged(QString resolution);
|
||||||
|
@ -216,6 +220,7 @@ private:
|
||||||
QString font_;
|
QString font_;
|
||||||
QString emojiFont_;
|
QString emojiFont_;
|
||||||
Presence presence_;
|
Presence presence_;
|
||||||
|
QString ringtone_;
|
||||||
QString microphone_;
|
QString microphone_;
|
||||||
QString camera_;
|
QString camera_;
|
||||||
QString cameraResolution_;
|
QString cameraResolution_;
|
||||||
|
@ -286,6 +291,7 @@ private:
|
||||||
QComboBox *fontSizeCombo_;
|
QComboBox *fontSizeCombo_;
|
||||||
QFontComboBox *fontSelectionCombo_;
|
QFontComboBox *fontSelectionCombo_;
|
||||||
QComboBox *emojiFontSelectionCombo_;
|
QComboBox *emojiFontSelectionCombo_;
|
||||||
|
QComboBox *ringtoneCombo_;
|
||||||
QComboBox *microphoneCombo_;
|
QComboBox *microphoneCombo_;
|
||||||
QComboBox *cameraCombo_;
|
QComboBox *cameraCombo_;
|
||||||
QComboBox *cameraResolutionCombo_;
|
QComboBox *cameraResolutionCombo_;
|
||||||
|
|
Loading…
Reference in a new issue