Make sure that a nullptr connection is not accessed in AccountEmoticonModel
I don't think it possible to open settings without an account connected anymore, however just to make sure I've made sure that a nullptr connection is handled in `AccountEmoticonsModel`. BUG: 478024
This commit is contained in:
@@ -24,6 +24,10 @@ int AccountEmoticonModel::rowCount(const QModelIndex &index) const
|
|||||||
|
|
||||||
QVariant AccountEmoticonModel::data(const QModelIndex &index, int role) const
|
QVariant AccountEmoticonModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
|
if (m_connection == nullptr) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
const auto &row = index.row();
|
const auto &row = index.row();
|
||||||
const auto &image = m_images->images[row];
|
const auto &image = m_images->images[row];
|
||||||
if (role == UrlRole) {
|
if (role == UrlRole) {
|
||||||
@@ -92,6 +96,10 @@ void AccountEmoticonModel::setConnection(Connection *connection)
|
|||||||
|
|
||||||
void AccountEmoticonModel::reloadEmoticons()
|
void AccountEmoticonModel::reloadEmoticons()
|
||||||
{
|
{
|
||||||
|
if (m_connection == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject json;
|
QJsonObject json;
|
||||||
if (m_connection->hasAccountData("im.ponies.user_emotes"_ls)) {
|
if (m_connection->hasAccountData("im.ponies.user_emotes"_ls)) {
|
||||||
json = m_connection->accountData("im.ponies.user_emotes"_ls)->contentJson();
|
json = m_connection->accountData("im.ponies.user_emotes"_ls)->contentJson();
|
||||||
@@ -104,6 +112,10 @@ void AccountEmoticonModel::reloadEmoticons()
|
|||||||
|
|
||||||
void AccountEmoticonModel::deleteEmoticon(int index)
|
void AccountEmoticonModel::deleteEmoticon(int index)
|
||||||
{
|
{
|
||||||
|
if (m_connection == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject data;
|
QJsonObject data;
|
||||||
m_images->images.removeAt(index);
|
m_images->images.removeAt(index);
|
||||||
m_images->fillJson(&data);
|
m_images->fillJson(&data);
|
||||||
@@ -112,6 +124,10 @@ void AccountEmoticonModel::deleteEmoticon(int index)
|
|||||||
|
|
||||||
void AccountEmoticonModel::setEmoticonBody(int index, const QString &text)
|
void AccountEmoticonModel::setEmoticonBody(int index, const QString &text)
|
||||||
{
|
{
|
||||||
|
if (m_connection == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_images->images[index].body = text;
|
m_images->images[index].body = text;
|
||||||
QJsonObject data;
|
QJsonObject data;
|
||||||
m_images->fillJson(&data);
|
m_images->fillJson(&data);
|
||||||
@@ -120,6 +136,10 @@ void AccountEmoticonModel::setEmoticonBody(int index, const QString &text)
|
|||||||
|
|
||||||
void AccountEmoticonModel::setEmoticonShortcode(int index, const QString &shortcode)
|
void AccountEmoticonModel::setEmoticonShortcode(int index, const QString &shortcode)
|
||||||
{
|
{
|
||||||
|
if (m_connection == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_images->images[index].shortcode = shortcode;
|
m_images->images[index].shortcode = shortcode;
|
||||||
QJsonObject data;
|
QJsonObject data;
|
||||||
m_images->fillJson(&data);
|
m_images->fillJson(&data);
|
||||||
@@ -128,6 +148,9 @@ void AccountEmoticonModel::setEmoticonShortcode(int index, const QString &shortc
|
|||||||
|
|
||||||
void AccountEmoticonModel::setEmoticonImage(int index, const QUrl &source)
|
void AccountEmoticonModel::setEmoticonImage(int index, const QUrl &source)
|
||||||
{
|
{
|
||||||
|
if (m_connection == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
doSetEmoticonImage(index, source);
|
doSetEmoticonImage(index, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,6 +189,9 @@ QCoro::Task<void> AccountEmoticonModel::doAddEmoticon(QUrl source, QString short
|
|||||||
|
|
||||||
void AccountEmoticonModel::addEmoticon(const QUrl &source, const QString &shortcode, const QString &description, const QString &type)
|
void AccountEmoticonModel::addEmoticon(const QUrl &source, const QString &shortcode, const QString &description, const QString &type)
|
||||||
{
|
{
|
||||||
|
if (m_connection == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
doAddEmoticon(source, shortcode, description, type);
|
doAddEmoticon(source, shortcode, description, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user