Fix ServerListModel
The server list needs to be populated on connection change as this is instantiated from QML
This commit is contained in:
@@ -16,41 +16,6 @@
|
|||||||
ServerListModel::ServerListModel(QObject *parent)
|
ServerListModel::ServerListModel(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
const auto stateConfig = KSharedConfig::openStateConfig();
|
|
||||||
const KConfigGroup serverGroup = stateConfig->group(QStringLiteral("Servers"));
|
|
||||||
|
|
||||||
QString domain = m_connection->domain();
|
|
||||||
|
|
||||||
// Add the user's homeserver
|
|
||||||
m_servers.append(Server{
|
|
||||||
domain,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
});
|
|
||||||
// Add matrix.org
|
|
||||||
m_servers.append(Server{
|
|
||||||
QStringLiteral("matrix.org"),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
});
|
|
||||||
// Add each of the saved custom servers
|
|
||||||
for (const auto &i : serverGroup.keyList()) {
|
|
||||||
m_servers.append(Server{
|
|
||||||
serverGroup.readEntry(i, QString()),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Add add server delegate entry
|
|
||||||
m_servers.append(Server{
|
|
||||||
QString(),
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ServerListModel::data(const QModelIndex &index, int role) const
|
QVariant ServerListModel::data(const QModelIndex &index, int role) const
|
||||||
@@ -165,6 +130,53 @@ void ServerListModel::setConnection(NeoChatConnection *connection)
|
|||||||
}
|
}
|
||||||
m_connection = connection;
|
m_connection = connection;
|
||||||
Q_EMIT connectionChanged();
|
Q_EMIT connectionChanged();
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerListModel::initialize()
|
||||||
|
{
|
||||||
|
if (m_connection == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beginResetModel();
|
||||||
|
const auto stateConfig = KSharedConfig::openStateConfig();
|
||||||
|
const KConfigGroup serverGroup = stateConfig->group(QStringLiteral("Servers"));
|
||||||
|
|
||||||
|
QString domain = m_connection->domain();
|
||||||
|
|
||||||
|
// Add the user's homeserver
|
||||||
|
m_servers.append(Server{
|
||||||
|
domain,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
});
|
||||||
|
// Add matrix.org
|
||||||
|
m_servers.append(Server{
|
||||||
|
QStringLiteral("matrix.org"),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
});
|
||||||
|
// Add each of the saved custom servers
|
||||||
|
for (const auto &i : serverGroup.keyList()) {
|
||||||
|
m_servers.append(Server{
|
||||||
|
serverGroup.readEntry(i, QString()),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Add add server delegate entry
|
||||||
|
m_servers.append(Server{
|
||||||
|
QString(),
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
});
|
||||||
|
beginResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_serverlistmodel.cpp"
|
#include "moc_serverlistmodel.cpp"
|
||||||
|
|||||||
@@ -111,4 +111,6 @@ private:
|
|||||||
QList<Server> m_servers;
|
QList<Server> m_servers;
|
||||||
QPointer<Quotient::QueryPublicRoomsJob> m_checkServerJob = nullptr;
|
QPointer<Quotient::QueryPublicRoomsJob> m_checkServerJob = nullptr;
|
||||||
NeoChatConnection *m_connection = nullptr;
|
NeoChatConnection *m_connection = nullptr;
|
||||||
|
|
||||||
|
void initialize();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user