Apply clang-format

This commit is contained in:
Tobias Fella
2020-12-25 22:23:35 +01:00
parent 6351454759
commit c449a8fafe
13 changed files with 1347 additions and 1352 deletions

View File

@@ -126,7 +126,7 @@ QVariantMap ChatDocumentHandler::getAutocompletionInfo()
if (cursor.block().text() == m_lastState) { if (cursor.block().text() == m_lastState) {
// ignore change, it was caused by autocompletion // ignore change, it was caused by autocompletion
return QVariantMap { return QVariantMap{
{"type", AutoCompletionType::Ignore}, {"type", AutoCompletionType::Ignore},
}; };
} }
@@ -141,7 +141,7 @@ QVariantMap ChatDocumentHandler::getAutocompletionInfo()
QString autoCompletePrefix = textBeforeCursor.section(" ", -1); QString autoCompletePrefix = textBeforeCursor.section(" ", -1);
if (autoCompletePrefix.isEmpty()) { if (autoCompletePrefix.isEmpty()) {
return QVariantMap { return QVariantMap{
{"type", AutoCompletionType::None}, {"type", AutoCompletionType::None},
}; };
} }
@@ -151,18 +151,18 @@ QVariantMap ChatDocumentHandler::getAutocompletionInfo()
if (autoCompletePrefix.startsWith("@")) { if (autoCompletePrefix.startsWith("@")) {
autoCompletePrefix.remove(0, 1); autoCompletePrefix.remove(0, 1);
return QVariantMap { return QVariantMap{
{"keyword", autoCompletePrefix}, {"keyword", autoCompletePrefix},
{"type", AutoCompletionType::User}, {"type", AutoCompletionType::User},
}; };
} }
return QVariantMap { return QVariantMap{
{"keyword", autoCompletePrefix}, {"keyword", autoCompletePrefix},
{"type", AutoCompletionType::Emoji}, {"type", AutoCompletionType::Emoji},
}; };
} }
return QVariantMap { return QVariantMap{
{"type", AutoCompletionType::None}, {"type", AutoCompletionType::None},
}; };
} }
@@ -194,8 +194,8 @@ void ChatDocumentHandler::postMessage(const QString &text, const QString &attach
if (cleanedText.indexOf(rainbowPrefix) == 0) { if (cleanedText.indexOf(rainbowPrefix) == 0) {
cleanedText = cleanedText.remove(0, rainbowPrefix.length()); cleanedText = cleanedText.remove(0, rainbowPrefix.length());
QString rainbowText; QString rainbowText;
QStringList rainbowColors {"#ff2b00", "#ff5500", "#ff8000", "#ffaa00", "#ffd500", "#ffff00", "#d4ff00", "#aaff00", "#80ff00", "#55ff00", "#2bff00", "#00ff00", "#00ff2b", "#00ff55", "#00ff80", "#00ffaa", "#00ffd5", "#00ffff", QStringList rainbowColors{"#ff2b00", "#ff5500", "#ff8000", "#ffaa00", "#ffd500", "#ffff00", "#d4ff00", "#aaff00", "#80ff00", "#55ff00", "#2bff00", "#00ff00", "#00ff2b", "#00ff55", "#00ff80", "#00ffaa", "#00ffd5", "#00ffff",
"#00d4ff", "#00aaff", "#007fff", "#0055ff", "#002bff", "#0000ff", "#2a00ff", "#5500ff", "#7f00ff", "#aa00ff", "#d400ff", "#ff00ff", "#ff00d4", "#ff00aa", "#ff0080", "#ff0055", "#ff002b", "#ff0000"}; "#00d4ff", "#00aaff", "#007fff", "#0055ff", "#002bff", "#0000ff", "#2a00ff", "#5500ff", "#7f00ff", "#aa00ff", "#d400ff", "#ff00ff", "#ff00d4", "#ff00aa", "#ff0080", "#ff0055", "#ff002b", "#ff0000"};
for (int i = 0; i < cleanedText.length(); i++) { for (int i = 0; i < cleanedText.length(); i++) {
rainbowText = rainbowText % QStringLiteral("<font color='") % rainbowColors.at(i % rainbowColors.length()) % "'>" % cleanedText.at(i) % "</font>"; rainbowText = rainbowText % QStringLiteral("<font color='") % rainbowColors.at(i % rainbowColors.length()) % "'>" % cleanedText.at(i) % "</font>";

View File

@@ -42,9 +42,9 @@
#include "csapi/wellknown.h" #include "csapi/wellknown.h"
#include "events/eventcontent.h" #include "events/eventcontent.h"
#include "events/roommessageevent.h" #include "events/roommessageevent.h"
#include "neochatconfig.h"
#include "neochatroom.h" #include "neochatroom.h"
#include "neochatuser.h" #include "neochatuser.h"
#include "neochatconfig.h"
#include "settings.h" #include "settings.h"
#include "utils.h" #include "utils.h"
#include <KStandardShortcut> #include <KStandardShortcut>
@@ -100,7 +100,6 @@ void Controller::loginWithCredentials(const QString &serverAddr, const QString &
return; return;
} }
if (deviceName.isEmpty()) { if (deviceName.isEmpty()) {
deviceName = "NeoChat " + QSysInfo::machineHostName() + " " + QSysInfo::productType() + " " + QSysInfo::productVersion() + " " + QSysInfo::currentCpuArchitecture(); deviceName = "NeoChat " + QSysInfo::machineHostName() + " " + QSysInfo::productType() + " " + QSysInfo::productVersion() + " " + QSysInfo::currentCpuArchitecture();
} }
@@ -252,7 +251,7 @@ void Controller::invokeLogin()
{ {
const auto accounts = SettingsGroup("Accounts").childGroups(); const auto accounts = SettingsGroup("Accounts").childGroups();
for (const auto &accountId : accounts) { for (const auto &accountId : accounts) {
AccountSettings account {accountId}; AccountSettings account{accountId};
if (!account.homeserver().isEmpty()) { if (!account.homeserver().isEmpty()) {
auto accessToken = loadAccessTokenFromKeyChain(account); auto accessToken = loadAccessTokenFromKeyChain(account);
@@ -293,7 +292,7 @@ void Controller::invokeLogin()
QByteArray Controller::loadAccessTokenFromFile(const AccountSettings &account) QByteArray Controller::loadAccessTokenFromFile(const AccountSettings &account)
{ {
QFile accountTokenFile {accessTokenFileName(account)}; QFile accountTokenFile{accessTokenFileName(account)};
if (accountTokenFile.open(QFile::ReadOnly)) { if (accountTokenFile.open(QFile::ReadOnly)) {
if (accountTokenFile.size() < 1024) { if (accountTokenFile.size() < 1024) {
return accountTokenFile.readAll(); return accountTokenFile.readAll();
@@ -331,7 +330,7 @@ QByteArray Controller::loadAccessTokenFromKeyChain(const AccountSettings &accoun
bool removed = false; bool removed = false;
bool saved = saveAccessTokenToKeyChain(account, accessToken); bool saved = saveAccessTokenToKeyChain(account, accessToken);
if (saved) { if (saved) {
QFile accountTokenFile {accessTokenFileName(account)}; QFile accountTokenFile{accessTokenFileName(account)};
removed = accountTokenFile.remove(); removed = accountTokenFile.remove();
} }
if (!(saved && removed)) { if (!(saved && removed)) {
@@ -354,7 +353,7 @@ QByteArray Controller::loadAccessTokenFromKeyChain(const AccountSettings &accoun
bool Controller::saveAccessTokenToFile(const AccountSettings &account, const QByteArray &accessToken) bool Controller::saveAccessTokenToFile(const AccountSettings &account, const QByteArray &accessToken)
{ {
// (Re-)Make a dedicated file for access_token. // (Re-)Make a dedicated file for access_token.
QFile accountTokenFile {accessTokenFileName(account)}; QFile accountTokenFile{accessTokenFileName(account)};
accountTokenFile.remove(); // Just in case accountTokenFile.remove(); // Just in case
auto fileDir = QFileInfo(accountTokenFile).dir(); auto fileDir = QFileInfo(accountTokenFile).dir();
@@ -400,7 +399,7 @@ void Controller::joinRoom(Connection *c, const QString &alias)
} }
auto knownServer = alias.mid(alias.indexOf(":") + 1); auto knownServer = alias.mid(alias.indexOf(":") + 1);
auto joinRoomJob = c->joinRoom(alias, QStringList {knownServer}); auto joinRoomJob = c->joinRoom(alias, QStringList{knownServer});
Quotient::JoinRoomJob::connect(joinRoomJob, &JoinRoomJob::failure, [=] { Quotient::JoinRoomJob::connect(joinRoomJob, &JoinRoomJob::failure, [=] {
Q_EMIT errorOccured("Join Room Failed", joinRoomJob->errorString()); Q_EMIT errorOccured("Join Room Failed", joinRoomJob->errorString());
}); });
@@ -564,9 +563,8 @@ QList<QKeySequence> Controller::preferencesShortcuts() const
return KStandardShortcut::preferences(); return KStandardShortcut::preferences();
} }
NeochatDeleteDeviceJob::NeochatDeleteDeviceJob(const QString& deviceId, const Omittable<QJsonObject> &auth) NeochatDeleteDeviceJob::NeochatDeleteDeviceJob(const QString &deviceId, const Omittable<QJsonObject> &auth)
: Quotient::BaseJob(HttpVerb::Delete, QStringLiteral("DeleteDeviceJob"), : Quotient::BaseJob(HttpVerb::Delete, QStringLiteral("DeleteDeviceJob"), QStringLiteral("/_matrix/client/r0/devices/%1").arg(deviceId))
QStringLiteral("/_matrix/client/r0/devices/%1").arg(deviceId))
{ {
QJsonObject _data; QJsonObject _data;
addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth); addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth);

View File

@@ -130,9 +130,10 @@ public:
explicit NeochatChangePasswordJob(const QString &newPassword, bool logoutDevices, const Omittable<QJsonObject> &auth = none); explicit NeochatChangePasswordJob(const QString &newPassword, bool logoutDevices, const Omittable<QJsonObject> &auth = none);
}; };
class NeochatDeleteDeviceJob : public BaseJob { class NeochatDeleteDeviceJob : public BaseJob
{
public: public:
explicit NeochatDeleteDeviceJob(const QString& deviceId, const Omittable<QJsonObject> &auth = none); explicit NeochatDeleteDeviceJob(const QString &deviceId, const Omittable<QJsonObject> &auth = none);
}; };
#endif // CONTROLLER_H #endif // CONTROLLER_H

View File

@@ -21,25 +21,25 @@ DevicesModel::DevicesModel(QObject *parent)
}); });
} }
QVariant DevicesModel::data(const QModelIndex& index, int role) const QVariant DevicesModel::data(const QModelIndex &index, int role) const
{ {
if(index.row() < 0 || index.row() >= rowCount(QModelIndex())) if (index.row() < 0 || index.row() >= rowCount(QModelIndex()))
return QVariant(); return QVariant();
switch(role) { switch (role) {
case Id: case Id:
return m_devices[index.row()].deviceId; return m_devices[index.row()].deviceId;
case DisplayName: case DisplayName:
return m_devices[index.row()].displayName; return m_devices[index.row()].displayName;
case LastIp: case LastIp:
return m_devices[index.row()].lastSeenIp; return m_devices[index.row()].lastSeenIp;
case LastTimestamp: case LastTimestamp:
if(m_devices[index.row()].lastSeenTs) if (m_devices[index.row()].lastSeenTs)
return *m_devices[index.row()].lastSeenTs; return *m_devices[index.row()].lastSeenTs;
} }
return QVariant(); return QVariant();
} }
int DevicesModel::rowCount(const QModelIndex& parent) const int DevicesModel::rowCount(const QModelIndex &parent) const
{ {
return m_devices.size(); return m_devices.size();
} }

View File

@@ -27,9 +27,9 @@ public:
DevicesModel(QObject *parent = nullptr); DevicesModel(QObject *parent = nullptr);
QVariant data(const QModelIndex & index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex & parent) const override; int rowCount(const QModelIndex &parent) const override;
Q_INVOKABLE void logout(int index, const QString &password); Q_INVOKABLE void logout(int index, const QString &password);
Q_INVOKABLE void setName(int index, const QString &name); Q_INVOKABLE void setName(int index, const QString &name);

File diff suppressed because it is too large Load Diff

View File

@@ -28,6 +28,7 @@
#include "controller.h" #include "controller.h"
#include "csapi/joining.h" #include "csapi/joining.h"
#include "csapi/leaving.h" #include "csapi/leaving.h"
#include "devicesmodel.h"
#include "emojimodel.h" #include "emojimodel.h"
#include "matriximageprovider.h" #include "matriximageprovider.h"
#include "messageeventmodel.h" #include "messageeventmodel.h"
@@ -41,7 +42,6 @@
#include "sortfilterroomlistmodel.h" #include "sortfilterroomlistmodel.h"
#include "userdirectorylistmodel.h" #include "userdirectorylistmodel.h"
#include "userlistmodel.h" #include "userlistmodel.h"
#include "devicesmodel.h"
using namespace Quotient; using namespace Quotient;
@@ -83,8 +83,7 @@ int main(int argc, char *argv[])
#ifdef NEOCHAT_FLATPAK #ifdef NEOCHAT_FLATPAK
// Copy over the included FontConfig configuration to the // Copy over the included FontConfig configuration to the
// app's config dir: // app's config dir:
QFile::copy("/app/etc/fonts/conf.d/99-noto-mono-color-emoji.conf", QFile::copy("/app/etc/fonts/conf.d/99-noto-mono-color-emoji.conf", "/var/config/fontconfig/conf.d/99-noto-mono-color-emoji.conf");
"/var/config/fontconfig/conf.d/99-noto-mono-color-emoji.conf");
#endif #endif
Clipboard clipboard; Clipboard clipboard;

View File

@@ -61,8 +61,8 @@ MessageEventModel::MessageEventModel(QObject *parent)
return; return;
} }
m_currentRoom->getPreviousContent(50); m_currentRoom->getPreviousContent(50);
connect(this, &QAbstractListModel::rowsInserted, this, [=](){ connect(this, &QAbstractListModel::rowsInserted, this, [=]() {
if(m_currentRoom->readMarkerEventId().isEmpty()) { if (m_currentRoom->readMarkerEventId().isEmpty()) {
return; return;
} }
const auto it = m_currentRoom->findInTimeline(m_currentRoom->readMarkerEventId()); const auto it = m_currentRoom->findInTimeline(m_currentRoom->readMarkerEventId());
@@ -295,7 +295,7 @@ int MessageEventModel::rowCount(const QModelIndex &parent) const
inline QVariantMap userAtEvent(NeoChatUser *user, NeoChatRoom *room, const RoomEvent &evt) inline QVariantMap userAtEvent(NeoChatUser *user, NeoChatRoom *room, const RoomEvent &evt)
{ {
Q_UNUSED(evt) Q_UNUSED(evt)
return QVariantMap { return QVariantMap{
{"isLocalUser", user->id() == room->localUser()->id()}, {"isLocalUser", user->id() == room->localUser()->id()},
{"id", user->id()}, {"id", user->id()},
{"avatarMediaId", user->avatarMediaId(room)}, {"avatarMediaId", user->avatarMediaId(room)},
@@ -485,7 +485,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
}; };
const auto &replyEvt = **replyIt; const auto &replyEvt = **replyIt;
return QVariantMap {{"eventId", replyEventId}, {"display", m_currentRoom->eventToString(replyEvt, Qt::RichText)}, {"author", userAtEvent(static_cast<NeoChatUser *>(m_currentRoom->user(replyEvt.senderId())), m_currentRoom, evt)}}; return QVariantMap{{"eventId", replyEventId}, {"display", m_currentRoom->eventToString(replyEvt, Qt::RichText)}, {"author", userAtEvent(static_cast<NeoChatUser *>(m_currentRoom->user(replyEvt.senderId())), m_currentRoom, evt)}};
} }
if (role == ShowAuthorRole) { if (role == ShowAuthorRole) {
@@ -539,7 +539,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
authors.append(userAtEvent(author, m_currentRoom, evt)); authors.append(userAtEvent(author, m_currentRoom, evt));
} }
bool hasLocalUser = i.value().contains(static_cast<NeoChatUser *>(m_currentRoom->localUser())); bool hasLocalUser = i.value().contains(static_cast<NeoChatUser *>(m_currentRoom->localUser()));
res.append(QVariantMap {{"reaction", i.key()}, {"count", i.value().count()}, {"authors", authors}, {"hasLocalUser", hasLocalUser}}); res.append(QVariantMap{{"reaction", i.key()}, {"count", i.value().count()}, {"authors", authors}, {"hasLocalUser", hasLocalUser}});
++i; ++i;
} }

View File

@@ -29,10 +29,10 @@
#include "events/roompowerlevelsevent.h" #include "events/roompowerlevelsevent.h"
#include "events/typingevent.h" #include "events/typingevent.h"
#include "jobs/downloadfilejob.h" #include "jobs/downloadfilejob.h"
#include "neochatconfig.h"
#include "notificationsmanager.h" #include "notificationsmanager.h"
#include "user.h" #include "user.h"
#include "utils.h" #include "utils.h"
#include "neochatconfig.h"
#include <KLocalizedString> #include <KLocalizedString>
@@ -50,7 +50,7 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
return; return;
} }
const RoomEvent *lastEvent = messageEvents().rbegin()->get(); const RoomEvent *lastEvent = messageEvents().rbegin()->get();
if(lastEvent->originTimestamp() < QDateTime::currentDateTime().addSecs(-60)) { if (lastEvent->originTimestamp() < QDateTime::currentDateTime().addSecs(-60)) {
return; return;
} }
if (lastEvent->isStateEvent()) { if (lastEvent->isStateEvent()) {
@@ -71,11 +71,9 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
NotificationsManager::instance().postNotification(this, displayName(), sender->displayname(this), eventToString(*lastEvent), avatar_image); NotificationsManager::instance().postNotification(this, displayName(), sender->displayname(this), eventToString(*lastEvent), avatar_image);
}); });
connect(this, &Room::aboutToAddHistoricalMessages, connect(this, &Room::aboutToAddHistoricalMessages, this, &NeoChatRoom::readMarkerLoadedChanged);
this, &NeoChatRoom::readMarkerLoadedChanged);
connect(this, &Quotient::Room::eventsHistoryJobChanged, connect(this, &Quotient::Room::eventsHistoryJobChanged, this, &NeoChatRoom::lastActiveTimeChanged);
this, &NeoChatRoom::lastActiveTimeChanged);
} }
void NeoChatRoom::uploadFile(const QUrl &url, const QString &body) void NeoChatRoom::uploadFile(const QUrl &url, const QString &body)
@@ -173,7 +171,6 @@ QString NeoChatRoom::lastEventToString() const
return QLatin1String(""); return QLatin1String("");
} }
bool NeoChatRoom::isEventHighlighted(const RoomEvent *e) const bool NeoChatRoom::isEventHighlighted(const RoomEvent *e) const
{ {
return highlights.contains(e); return highlights.contains(e);
@@ -365,7 +362,7 @@ QString NeoChatRoom::eventToString(const RoomEvent &evt, Qt::TextFormat format,
if (!e.prevContent() || e.membership() != e.prevContent()->membership) { if (!e.prevContent() || e.membership() != e.prevContent()->membership) {
return e.membership() == MembershipType::Invite ? i18n("invited %1 to the room", subjectName) : i18n("joined the room"); return e.membership() == MembershipType::Invite ? i18n("invited %1 to the room", subjectName) : i18n("joined the room");
} }
QString text {}; QString text{};
if (e.isRename()) { if (e.isRename()) {
if (!e.newDisplayName().has_value()) { if (!e.newDisplayName().has_value()) {
text = i18n("cleared their display name"); text = i18n("cleared their display name");
@@ -434,7 +431,7 @@ void NeoChatRoom::changeAvatar(const QUrl &localFile)
const auto job = connection()->uploadFile(localFile.toLocalFile()); const auto job = connection()->uploadFile(localFile.toLocalFile());
if (isJobRunning(job)) { if (isJobRunning(job)) {
connect(job, &BaseJob::success, this, [this, job] { connect(job, &BaseJob::success, this, [this, job] {
connection()->callApi<SetRoomStateWithKeyJob>(id(), "m.room.avatar", localUser()->id(), QJsonObject {{"url", job->contentUri()}}); connection()->callApi<SetRoomStateWithKeyJob>(id(), "m.room.avatar", localUser()->id(), QJsonObject{{"url", job->contentUri()}});
}); });
} }
} }

View File

@@ -11,8 +11,8 @@
#include <KLocalizedString> #include <KLocalizedString>
#include <KNotification> #include <KNotification>
#include "neochatconfig.h"
#include "controller.h" #include "controller.h"
#include "neochatconfig.h"
NotificationsManager &NotificationsManager::instance() NotificationsManager &NotificationsManager::instance()
{ {

View File

@@ -21,7 +21,7 @@ class NotificationsManager : public QObject
public: public:
static NotificationsManager &instance(); static NotificationsManager &instance();
Q_INVOKABLE void postNotification(NeoChatRoom *room, const QString& roomName, const QString& sender, const QString& text, const QImage& icon); Q_INVOKABLE void postNotification(NeoChatRoom *room, const QString &roomName, const QString &sender, const QString &text, const QImage &icon);
private: private:
NotificationsManager(QObject *parent = nullptr); NotificationsManager(QObject *parent = nullptr);

View File

@@ -115,7 +115,7 @@ void PublicRoomListModel::next(int count)
return; return;
} }
job = m_connection->callApi<QueryPublicRoomsJob>(m_server, count, nextBatch, QueryPublicRoomsJob::Filter {m_keyword}); job = m_connection->callApi<QueryPublicRoomsJob>(m_server, count, nextBatch, QueryPublicRoomsJob::Filter{m_keyword});
connect(job, &BaseJob::finished, this, [=] { connect(job, &BaseJob::finished, this, [=] {
attempted = true; attempted = true;

View File

@@ -20,11 +20,11 @@
namespace utils namespace utils
{ {
static const QRegularExpression removeReplyRegex {"> <.*?>.*?\\n\\n", QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression removeReplyRegex{"> <.*?>.*?\\n\\n", QRegularExpression::DotMatchesEverythingOption};
static const QRegularExpression removeRichReplyRegex {"<mx-reply>.*?</mx-reply>", QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression removeRichReplyRegex{"<mx-reply>.*?</mx-reply>", QRegularExpression::DotMatchesEverythingOption};
static const QRegularExpression codePillRegExp {"<pre><code[^>]*>(.*?)</code></pre>", QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression codePillRegExp{"<pre><code[^>]*>(.*?)</code></pre>", QRegularExpression::DotMatchesEverythingOption};
static const QRegularExpression userPillRegExp {"<a href=\"https://matrix.to/#/@.*?:.*?\">(.*?)</a>", QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression userPillRegExp{"<a href=\"https://matrix.to/#/@.*?:.*?\">(.*?)</a>", QRegularExpression::DotMatchesEverythingOption};
static const QRegularExpression strikethroughRegExp {"<del>(.*?)</del>", QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression strikethroughRegExp{"<del>(.*?)</del>", QRegularExpression::DotMatchesEverythingOption};
} // namespace utils } // namespace utils
#endif #endif