WIP notification settings, doesn't actually work

This commit is contained in:
apa420
2018-08-09 15:41:03 +02:00
parent 7a9af4ae84
commit b68c7ded5f
11 changed files with 230 additions and 3 deletions
@@ -0,0 +1,62 @@
#include "NotificationController.hpp"
#include "Application.hpp"
#include "controllers/notifications/NotificationModel.hpp"
namespace chatterino {
NotificationController::NotificationController()
{
}
void NotificationController::initialize(Settings &settings, Paths &paths)
{
this->initialized_ = true;
for (const QString &channelName : this->notificationSetting_.getValue()) {
this->notificationVector.appendItem(channelName);
}
this->notificationVector.delayedItemsChanged.connect([this] { //
this->notificationSetting_.setValue(
this->notificationVector.getVector());
});
}
void NotificationController::updateChannelNotification(
const QString &channelName)
{
if (isChannelNotified(channelName)) {
removeChannelNotification(channelName);
} else {
addChannelNotification(channelName);
}
}
bool NotificationController::isChannelNotified(const QString &channelName)
{
const auto &vector = notificationSetting_.getValue();
return std::find(vector.begin(), vector.end(), channelName) != vector.end();
}
void NotificationController::addChannelNotification(const QString &channelName)
{
auto vector = notificationSetting_.getValue();
vector.push_back(channelName);
notificationSetting_.setValue(vector);
}
void NotificationController::removeChannelNotification(
const QString &channelName)
{
auto vector = notificationSetting_.getValue();
vector.erase(std::find(vector.begin(), vector.end(), channelName));
notificationSetting_.setValue(vector);
}
NotificationModel *NotificationController::createModel(QObject *parent)
{
NotificationModel *model = new NotificationModel(parent);
model->init(&this->notificationVector);
return model;
}
} // namespace chatterino
@@ -0,0 +1,37 @@
#pragma once
#include "common/SignalVector.hpp"
#include "singletons/Settings.hpp"
namespace chatterino {
class Settings;
class Paths;
class NotificationModel;
class NotificationController final : public Singleton
{
public:
NotificationController();
virtual void initialize(Settings &settings, Paths &paths) override;
bool isChannelNotified(const QString &channelName);
void updateChannelNotification(const QString &channelName);
void addChannelNotification(const QString &channelName);
void removeChannelNotification(const QString &channelName);
UnsortedSignalVector<QString> notificationVector;
NotificationModel *createModel(QObject *parent);
private:
bool initialized_ = false;
ChatterinoSetting<std::vector<QString>> notificationSetting_ = {
"/notifications/channels"};
};
} // namespace chatterino