Add menu actions to set presence

master
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; mtx::http::SyncOpts opts;
opts.timeout = 0; opts.timeout = 0;
opts.set_presence = currentPresence();
http::client()->sync( http::client()->sync(
opts, opts,
std::bind( std::bind(
@ -996,6 +998,7 @@ void
ChatPage::trySync() ChatPage::trySync()
{ {
mtx::http::SyncOpts opts; mtx::http::SyncOpts opts;
opts.set_presence = currentPresence();
if (!connectivityTimer_.isActive()) if (!connectivityTimer_.isActive())
connectivityTimer_.start(); 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 void
ChatPage::initialSyncHandler(const mtx::responses::Sync &res, mtx::http::RequestErr err) ChatPage::initialSyncHandler(const mtx::responses::Sync &res, mtx::http::RequestErr err)
{ {

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

@ -31,6 +31,7 @@
#include "MainWindow.h" #include "MainWindow.h"
#include "Splitter.h" #include "Splitter.h"
#include "UserInfoWidget.h" #include "UserInfoWidget.h"
#include "UserSettingsPage.h"
#include "ui/Avatar.h" #include "ui/Avatar.h"
#include "ui/FlatButton.h" #include "ui/FlatButton.h"
#include "ui/OverlayModal.h" #include "ui/OverlayModal.h"
@ -123,6 +124,28 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
if (ok && !text.isEmpty()) if (ok && !text.isEmpty())
ChatPage::instance()->setStatus(text); 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 void

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

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

Loading…
Cancel
Save