Adds option to mute ping sound for specific channels (#990)

Co-Authored-By: hemirt <hemirt@hemirt.com>
This commit is contained in:
hemirt
2019-05-10 22:36:37 +02:00
committed by pajlada
parent 9654650bee
commit c43c1dc207
9 changed files with 195 additions and 3 deletions
+70
View File
@@ -0,0 +1,70 @@
#include "controllers/pings/PingController.hpp"
#include "controllers/pings/PingModel.hpp"
namespace chatterino {
void PingController::initialize(Settings &settings, Paths &paths)
{
this->initialized_ = true;
for (const QString &channelName : this->pingSetting_.getValue())
{
this->channelVector.appendItem(channelName);
}
this->channelVector.delayedItemsChanged.connect([this] { //
this->pingSetting_.setValue(this->channelVector.getVector());
});
}
PingModel *PingController::createModel(QObject *parent)
{
PingModel *model = new PingModel(parent);
model->init(&this->channelVector);
return model;
}
bool PingController::isMuted(const QString &channelName)
{
for (const auto &channel : this->channelVector.getVector())
{
if (channelName.toLower() == channel.toLower())
{
return true;
}
}
return false;
}
void PingController::muteChannel(const QString &channelName)
{
channelVector.appendItem(channelName);
}
void PingController::unmuteChannel(const QString &channelName)
{
for (std::vector<int>::size_type i = 0;
i != channelVector.getVector().size(); i++)
{
if (channelVector.getVector()[i].toLower() == channelName.toLower())
{
channelVector.removeItem(i);
i--;
}
}
}
bool PingController::toggleMuteChannel(const QString &channelName)
{
if (this->isMuted(channelName))
{
unmuteChannel(channelName);
return false;
}
else
{
muteChannel(channelName);
return true;
}
}
} // namespace chatterino
+36
View File
@@ -0,0 +1,36 @@
#pragma once
#include <QObject>
#include "common/SignalVector.hpp"
#include "common/Singleton.hpp"
#include "singletons/Settings.hpp"
namespace chatterino {
class Settings;
class Paths;
class PingModel;
class PingController final : public Singleton, private QObject
{
public:
virtual void initialize(Settings &settings, Paths &paths) override;
bool isMuted(const QString &channelName);
void muteChannel(const QString &channelName);
void unmuteChannel(const QString &channelName);
bool toggleMuteChannel(const QString &channelName);
PingModel *createModel(QObject *parent);
private:
bool initialized_ = false;
UnsortedSignalVector<QString> channelVector;
ChatterinoSetting<std::vector<QString>> pingSetting_ = {"/pings/muted"};
};
} // namespace chatterino
+28
View File
@@ -0,0 +1,28 @@
#include "PingModel.hpp"
#include "Application.hpp"
#include "singletons/Settings.hpp"
#include "util/StandardItemHelper.hpp"
namespace chatterino {
PingModel::PingModel(QObject *parent)
: SignalVectorModel<QString>(1, parent)
{
}
// turn a vector item into a model row
QString PingModel::getItemFromRow(std::vector<QStandardItem *> &row,
const QString &original)
{
return QString(row[0]->data(Qt::DisplayRole).toString());
}
// turn a model
void PingModel::getRowFromItem(const QString &item,
std::vector<QStandardItem *> &row)
{
setStringItem(row[0], item);
}
} // namespace chatterino
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <QObject>
#include "common/SignalVectorModel.hpp"
#include "controllers/notifications/NotificationController.hpp"
namespace chatterino {
class PingController;
class PingModel : public SignalVectorModel<QString>
{
explicit PingModel(QObject *parent);
protected:
// turn a vector item into a model row
virtual QString getItemFromRow(std::vector<QStandardItem *> &row,
const QString &original) override;
// turns a row in the model into a vector item
virtual void getRowFromItem(const QString &item,
std::vector<QStandardItem *> &row) override;
friend class PingController;
};
} // namespace chatterino