Add menu actions to set presence

pull/216/head
Nicolas Werner 5 years ago
parent 96f4169be9
commit f2bfa61e08
  1. 18
      src/ChatPage.cpp
  2. 2
      src/ChatPage.h
  3. 23
      src/UserInfoWidget.cpp
  4. 21
      src/UserSettingsPage.cpp
  5. 14
      src/UserSettingsPage.h

@ -986,6 +986,8 @@ ChatPage::startInitialSync()
mtx::http::SyncOpts opts;
opts.timeout = 0;
opts.set_presence = currentPresence();
http::client()->sync(
opts,
std::bind(
@ -996,6 +998,7 @@ void
ChatPage::trySync()
{
mtx::http::SyncOpts opts;
opts.set_presence = currentPresence();
if (!connectivityTimer_.isActive())
connectivityTimer_.start();
@ -1241,6 +1244,21 @@ ChatPage::setStatus(const QString &status)
});
}
mtx::presence::PresenceState
ChatPage::currentPresence() const
{
switch (userSettings_->presence()) {
case UserSettings::Presence::Online:
return mtx::presence::online;
case UserSettings::Presence::Unavailable:
return mtx::presence::unavailable;
case UserSettings::Presence::Offline:
return mtx::presence::offline;
default:
return mtx::presence::online;
}
}
void
ChatPage::initialSyncHandler(const mtx::responses::Sync &res, mtx::http::RequestErr err)
{

@ -92,7 +92,7 @@ public:
QString status() const;
void setStatus(const QString &status);
mtx::presence::PresenceState currentPresence() const { return mtx::presence::online; }
mtx::presence::PresenceState currentPresence() const;
public slots:
void leaveRoom(const QString &room_id);

@ -31,6 +31,7 @@
#include "MainWindow.h"
#include "Splitter.h"
#include "UserInfoWidget.h"
#include "UserSettingsPage.h"
#include "ui/Avatar.h"
#include "ui/FlatButton.h"
#include "ui/OverlayModal.h"
@ -123,6 +124,28 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
if (ok && !text.isEmpty())
ChatPage::instance()->setStatus(text);
});
auto setAutoPresence = menu->addAction(tr("Set presence automatically"));
connect(setAutoPresence, &QAction::triggered, this, [this]() {
ChatPage::instance()->userSettings()->setPresence(
UserSettings::Presence::AutomaticPresence);
ChatPage::instance()->setStatus(ChatPage::instance()->status());
});
auto setOnline = menu->addAction(tr("Online"));
connect(setOnline, &QAction::triggered, this, [this]() {
ChatPage::instance()->userSettings()->setPresence(UserSettings::Presence::Online);
ChatPage::instance()->setStatus(ChatPage::instance()->status());
});
auto setUnavailable = menu->addAction(tr("Unavailable"));
connect(setUnavailable, &QAction::triggered, this, [this]() {
ChatPage::instance()->userSettings()->setPresence(
UserSettings::Presence::Unavailable);
ChatPage::instance()->setStatus(ChatPage::instance()->status());
});
auto setOffline = menu->addAction(tr("Offline"));
connect(setOffline, &QAction::triggered, this, [this]() {
ChatPage::instance()->userSettings()->setPresence(UserSettings::Presence::Offline);
ChatPage::instance()->setStatus(ChatPage::instance()->status());
});
}
void

@ -34,6 +34,7 @@
#include <QStandardPaths>
#include <QString>
#include <QTextStream>
#include <QtQml>
#include "Cache.h"
#include "Config.h"
@ -46,7 +47,11 @@
#include "config/nheko.h"
UserSettings::UserSettings() { load(); }
UserSettings::UserSettings()
{
qRegisterMetaType<UserSettings::Presence>();
load();
}
void
UserSettings::load()
@ -72,6 +77,9 @@ UserSettings::load()
decryptSidebar_ = settings.value("user/decrypt_sidebar", true).toBool();
emojiFont_ = settings.value("user/emoji_font_family", "default").toString();
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
presence_ =
settings.value("user/presence", QVariant::fromValue(Presence::AutomaticPresence))
.value<Presence>();
applyTheme();
}
@ -243,6 +251,16 @@ UserSettings::setEmojiFontFamily(QString family)
save();
}
void
UserSettings::setPresence(Presence state)
{
if (state == presence_)
return;
presence_ = state;
emit presenceChanged(state);
save();
}
void
UserSettings::setTheme(QString theme)
{
@ -337,6 +355,7 @@ UserSettings::save()
settings.setValue("theme", theme());
settings.setValue("font_family", font_);
settings.setValue("emoji_font_family", emojiFont_);
settings.setValue("presence", QVariant::fromValue(presence_));
settings.endGroup();

@ -68,10 +68,20 @@ class UserSettings : public QObject
Q_PROPERTY(QString font READ font WRITE setFontFamily NOTIFY fontChanged)
Q_PROPERTY(
QString emojiFont READ emojiFont WRITE setEmojiFontFamily NOTIFY emojiFontChanged)
Q_PROPERTY(Presence presence READ presence WRITE setPresence NOTIFY presenceChanged)
public:
UserSettings();
enum class Presence
{
AutomaticPresence,
Online,
Unavailable,
Offline,
};
Q_ENUM(Presence);
void save();
void load();
void applyTheme();
@ -93,6 +103,7 @@ public:
void setDesktopNotifications(bool state);
void setAvatarCircles(bool state);
void setDecryptSidebar(bool state);
void setPresence(Presence state);
QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; }
bool messageHoverHighlight() const { return messageHoverHighlight_; }
@ -112,6 +123,7 @@ public:
double fontSize() const { return baseFontSize_; }
QString font() const { return font_; }
QString emojiFont() const { return emojiFont_; }
Presence presence() const { return presence_; }
signals:
void groupViewStateChanged(bool state);
@ -132,6 +144,7 @@ signals:
void fontSizeChanged(double state);
void fontChanged(QString state);
void emojiFontChanged(QString state);
void presenceChanged(Presence state);
private:
// Default to system theme if QT_QPA_PLATFORMTHEME var is set.
@ -157,6 +170,7 @@ private:
double baseFontSize_;
QString font_;
QString emojiFont_;
Presence presence_;
};
class HorizontalLine : public QFrame

Loading…
Cancel
Save