Reformat code
This commit is contained in:
parent
6df6ea1523
commit
d83471009f
26 changed files with 810 additions and 698 deletions
33
.clang-format
Normal file
33
.clang-format
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
CompactNamespaces: 'false'
|
||||
DisableFormat: 'false'
|
||||
IndentCaseLabels: 'true'
|
||||
IndentPPDirectives: BeforeHash
|
||||
IndentWidth: '4'
|
||||
Language: Cpp
|
||||
NamespaceIndentation: All
|
||||
PointerAlignment: Left
|
||||
ReflowComments: 'true'
|
||||
SortIncludes: 'true'
|
||||
SortUsingDeclarations: 'true'
|
||||
SpacesInCStyleCastParentheses: 'false'
|
||||
Standard: Cpp11
|
||||
TabWidth: '0'
|
||||
UseTab: Never
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
BraceWrapping:
|
||||
AfterEnum: true
|
||||
AccessModifierOffset: -4
|
||||
SpaceAfterTemplateKeyword: 'false'
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
ColumnLimit: 120
|
||||
AllowShortBlocksOnASingleLine: 'false'
|
||||
AllowShortCaseLabelsOnASingleLine: 'false'
|
||||
AllowShortFunctionsOnASingleLine: 'Empty'
|
||||
AllowShortLambdasOnASingleLine: 'Empty'
|
||||
AllowShortLoopsOnASingleLine: 'false'
|
||||
SeparateDefinitionBlocks : 'Always'
|
8
.editorconfig
Normal file
8
.editorconfig
Normal file
|
@ -0,0 +1,8 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
tab_width = 4
|
||||
max_line_length = 120
|
30
README.md
30
README.md
|
@ -1,6 +1,8 @@
|
|||
# Trinity
|
||||
A Qt5 QML Matrix client, which supports end-to-end encryption (WIP) and has a Discord-like interface.
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
* Basic messaging capabilities
|
||||
* Sending and recieving markdown messages, formatting can be disabled
|
||||
|
@ -13,28 +15,18 @@ A Qt5 QML Matrix client, which supports end-to-end encryption (WIP) and has a Di
|
|||
* Start direct chats with other members
|
||||
* Custom emote support
|
||||
|
||||
## Screenshots
|
||||

|
||||
## Installation
|
||||
|
||||
*Note: This is an outdated screenshot :-)*
|
||||
I'm not providing any pre-built binaries yet, so you must compile from source.
|
||||
|
||||
## Dependencies
|
||||
If you use Arch Linux, I maintain the [AUR package](https://aur.archlinux.org/packages/trinity-matrix-git).
|
||||
|
||||
## Building
|
||||
|
||||
Building Trinity is very easy, simply call CMake. Please make sure all the dependencies below are met.
|
||||
|
||||
### Dependencies
|
||||
* Qt5
|
||||
* WebEngine is also required
|
||||
* CMark
|
||||
* libolm
|
||||
|
||||
## Installation
|
||||
There's no pre-compiled binaries yet, but compiling from source is easily provided you have Qt5 installed. If you use
|
||||
Arch Linux, there's a [PKGBUILD available from the AUR](https://aur.archlinux.org/packages/trinity-matrix-git). Simply call it from `makepkg` or through your favorite AUR helper:
|
||||
|
||||
```
|
||||
$ aur sync trinity-matrix-git
|
||||
```
|
||||
|
||||
Since there's not a tagged release yet, there's only the git version available as a PKGBUILD at the moment.
|
||||
|
||||
## Licensing
|
||||
Trinity's source code is distributed under the GPLv3 license. See the `LICENSE` file for more details.
|
||||
|
||||
`resources/background.jpg` shown on the login page is from Death to Stock.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <vector>
|
||||
#include <QQmlContext>
|
||||
#include <vector>
|
||||
|
||||
class MatrixCore;
|
||||
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QApplication>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
class Desktop : public QObject
|
||||
{
|
||||
class Desktop : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_INVOKABLE void showTrayIcon(const bool shouldHide) {
|
||||
QApplication::setQuitOnLastWindowClosed(shouldHide);
|
||||
|
||||
if(shouldHide)
|
||||
if (shouldHide)
|
||||
icon->show();
|
||||
else
|
||||
icon->hide();
|
||||
|
@ -21,7 +20,7 @@ public:
|
|||
}
|
||||
|
||||
Q_INVOKABLE bool isTrayIconEnabled() {
|
||||
return icon->isVisible();;
|
||||
return icon->isVisible();
|
||||
}
|
||||
|
||||
QSystemTrayIcon* icon;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#ifndef DIRECTORYMODEL_H
|
||||
#define DIRECTORYMODEL_H
|
||||
|
||||
|
||||
class DirectoryModel
|
||||
{
|
||||
class DirectoryModel {
|
||||
public:
|
||||
DirectoryModel();
|
||||
};
|
||||
|
|
|
@ -5,13 +5,12 @@
|
|||
|
||||
#include "emote.h"
|
||||
|
||||
class EmoteListModel : public QAbstractListModel
|
||||
{
|
||||
class EmoteListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
int rowCount(const QModelIndex& parent) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
|
||||
void setList(QList<Emote*>* emotes) {
|
||||
this->emotes = emotes;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
#include <QString>
|
||||
|
||||
#include <olm/olm.h>
|
||||
|
||||
|
|
|
@ -6,8 +6,7 @@ class MatrixCore;
|
|||
struct Room;
|
||||
class Event;
|
||||
|
||||
class EventModel : public QAbstractListModel
|
||||
{
|
||||
class EventModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum EventRoles {
|
||||
|
@ -17,21 +16,21 @@ public:
|
|||
|
||||
EventModel(MatrixCore& matrix);
|
||||
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
int rowCount(const QModelIndex& parent) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
|
||||
void beginUpdate(const unsigned int num);
|
||||
|
||||
void endUpdate() {
|
||||
if(room)
|
||||
if (room)
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void beginHistory(int size);
|
||||
|
||||
void endHistory() {
|
||||
if(room)
|
||||
if (room)
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QJsonObject>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QJsonObject>
|
||||
#include <QObject>
|
||||
|
||||
#include "eventmodel.h"
|
||||
#include "room.h"
|
||||
#include "roomlistmodel.h"
|
||||
#include "membermodel.h"
|
||||
#include "roomlistsortmodel.h"
|
||||
#include "emote.h"
|
||||
#include "emotelistmodel.h"
|
||||
#include "encryption.h"
|
||||
#include "eventmodel.h"
|
||||
#include "membermodel.h"
|
||||
#include "room.h"
|
||||
#include "roomlistmodel.h"
|
||||
#include "roomlistsortmodel.h"
|
||||
|
||||
class Network;
|
||||
|
||||
class MatrixCore : public QObject
|
||||
{
|
||||
class MatrixCore : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString profileName MEMBER profileName CONSTANT)
|
||||
Q_PROPERTY(bool initialSyncComplete READ isInitialSyncComplete NOTIFY initialSyncFinished)
|
||||
|
@ -39,7 +38,11 @@ public:
|
|||
Encryption* encryption = nullptr;
|
||||
|
||||
// account
|
||||
Q_INVOKABLE void registerAccount(const QString& username, const QString& password, const QString& session = "", const QString& type = "");
|
||||
Q_INVOKABLE void registerAccount(
|
||||
const QString& username,
|
||||
const QString& password,
|
||||
const QString& session = "",
|
||||
const QString& type = "");
|
||||
|
||||
Q_INVOKABLE void login(const QString& username, const QString& password);
|
||||
Q_INVOKABLE void logout();
|
||||
|
@ -94,7 +97,14 @@ public:
|
|||
|
||||
void setMarkdownEnabled(const bool enabled);
|
||||
|
||||
void sendKeyToDevice(QString roomId, QString senderCurveIdentity, QString senderEdIdentity, QString session_id, QString session_key, QString user_id, QString device_id);
|
||||
void sendKeyToDevice(
|
||||
QString roomId,
|
||||
QString senderCurveIdentity,
|
||||
QString senderEdIdentity,
|
||||
QString session_id,
|
||||
QString session_key,
|
||||
QString user_id,
|
||||
QString device_id);
|
||||
|
||||
OlmOutboundGroupSession* currentSession = nullptr;
|
||||
QString currentSessionId, currentSessionKey;
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
class Room;
|
||||
|
||||
class MemberModel : public QAbstractListModel
|
||||
{
|
||||
class MemberModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum EventRoles {
|
||||
|
@ -15,9 +14,9 @@ public:
|
|||
SectionRole
|
||||
};
|
||||
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
int rowCount(const QModelIndex& parent) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
|
||||
void beginUpdate(const unsigned int num) {
|
||||
beginInsertRows(QModelIndex(), 0, num);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QUrl>
|
||||
|
||||
#include "requestsender.h"
|
||||
|
@ -17,8 +17,7 @@ public:
|
|||
QNetworkAccessManager* manager;
|
||||
QString homeserverURL, accessToken;
|
||||
|
||||
template<typename Fn>
|
||||
inline void postJSON(const QString& path, const QJsonObject object, Fn&& fn) {
|
||||
template<typename Fn> inline void postJSON(const QString& path, const QJsonObject object, Fn&& fn) {
|
||||
QNetworkRequest request(homeserverURL + path);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||
|
@ -38,7 +37,8 @@ public:
|
|||
}
|
||||
|
||||
template<typename Fn, typename ProgressFn>
|
||||
inline void postBinary(const QString& path, const QByteArray data, const QString mimeType, Fn&& fn, ProgressFn&& progressFn) {
|
||||
inline void
|
||||
postBinary(const QString& path, const QByteArray data, const QString mimeType, Fn&& fn, ProgressFn&& progressFn) {
|
||||
QNetworkRequest request(homeserverURL + path);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, mimeType);
|
||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||
|
@ -56,8 +56,7 @@ public:
|
|||
QObject::connect(reply, &QNetworkReply::uploadProgress, progressFn);
|
||||
}
|
||||
|
||||
template<typename Fn>
|
||||
inline void post(const QString& path, Fn&& fn) {
|
||||
template<typename Fn> inline void post(const QString& path, Fn&& fn) {
|
||||
QNetworkRequest request(homeserverURL + path);
|
||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||
|
||||
|
@ -90,8 +89,7 @@ public:
|
|||
manager->put(request, jsonPost);
|
||||
}
|
||||
|
||||
template<typename Fn>
|
||||
inline void putJSON(const QString& path, const QJsonObject object, Fn&& fn) {
|
||||
template<typename Fn> inline void putJSON(const QString& path, const QJsonObject object, Fn&& fn) {
|
||||
QNetworkRequest request(homeserverURL + path);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <QObject>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QObject>
|
||||
#include <functional>
|
||||
|
||||
class RequestSender : public QObject
|
||||
{
|
||||
class RequestSender : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
RequestSender(QObject* parent = nullptr) : QObject(parent) {}
|
||||
|
@ -22,8 +21,8 @@ public:
|
|||
std::function<void(QNetworkReply*)> fn;
|
||||
|
||||
void finished(QNetworkReply* reply) {
|
||||
if(reply->request().originatingObject() == this) {
|
||||
//qDebug() << reply->errorString();
|
||||
if (reply->request().originatingObject() == this) {
|
||||
// qDebug() << reply->errorString();
|
||||
|
||||
fn(reply);
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
|
||||
class EncryptionInformation : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -12,8 +12,7 @@ public:
|
|||
QString sessionId;
|
||||
};
|
||||
|
||||
class Event : public QObject
|
||||
{
|
||||
class Event : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString sender READ getSender NOTIFY senderChanged)
|
||||
Q_PROPERTY(QString msg READ getMsg NOTIFY msgChanged)
|
||||
|
@ -175,8 +174,7 @@ private:
|
|||
QString id, displayName, avatarURL;
|
||||
};
|
||||
|
||||
class Room : public QObject
|
||||
{
|
||||
class Room : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString id MEMBER id NOTIFY idChanged)
|
||||
Q_PROPERTY(QString topic MEMBER topic NOTIFY topicChanged)
|
||||
|
@ -188,7 +186,8 @@ class Room : public QObject
|
|||
Q_PROPERTY(QString highlightCount READ getHighlightCount NOTIFY highlightCountChanged)
|
||||
Q_PROPERTY(QString notificationCount READ getNotificationCount NOTIFY notificationCountChanged)
|
||||
Q_PROPERTY(bool direct READ getDirect NOTIFY directChanged)
|
||||
Q_PROPERTY(int notificationLevel READ getNotificationLevel WRITE setNotificationLevel NOTIFY notificationLevelChanged)
|
||||
Q_PROPERTY(
|
||||
int notificationLevel READ getNotificationLevel WRITE setNotificationLevel NOTIFY notificationLevelChanged)
|
||||
Q_PROPERTY(bool encrypted READ getEncrypted NOTIFY encryptionChanged)
|
||||
public:
|
||||
Room(QObject* parent = nullptr) : QObject(parent) {}
|
||||
|
@ -255,7 +254,7 @@ public:
|
|||
void setNotificationLevel(const int level, const bool skipSave = false) {
|
||||
notificationLevel = level;
|
||||
|
||||
if(!skipSave) {
|
||||
if (!skipSave) {
|
||||
QSettings settings;
|
||||
settings.beginGroup(id);
|
||||
settings.setValue("notificationLevel", notificationLevel);
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
class Room;
|
||||
|
||||
class RoomListModel : public QAbstractListModel
|
||||
{
|
||||
class RoomListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum EventRoles {
|
||||
|
@ -22,9 +21,9 @@ public:
|
|||
|
||||
RoomListModel(QList<Room*>& rooms);
|
||||
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
int rowCount(const QModelIndex& parent) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
|
||||
void beginInsertRoom() {
|
||||
beginInsertRows(QModelIndex(), rooms.size(), rooms.size());
|
||||
|
|
|
@ -2,37 +2,34 @@
|
|||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
class RoomListSortModel : public QSortFilterProxyModel
|
||||
{
|
||||
class RoomListSortModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
|
||||
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const;
|
||||
|
||||
Q_INVOKABLE unsigned int getOriginalIndex(const unsigned int i) const {
|
||||
auto const proxyIndex = index(i, 0);
|
||||
auto const sourceIndex = mapToSource(proxyIndex);
|
||||
|
||||
if(!sourceIndex.isValid())
|
||||
if (!sourceIndex.isValid())
|
||||
return 0;
|
||||
else
|
||||
return sourceIndex.row();
|
||||
}
|
||||
};
|
||||
|
||||
class MemberListSortModel : public QSortFilterProxyModel
|
||||
{
|
||||
class MemberListSortModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
|
||||
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const;
|
||||
|
||||
Q_INVOKABLE unsigned int getOriginalIndex(const unsigned int i) const {
|
||||
auto const proxyIndex = index(i, 0);
|
||||
auto const sourceIndex = mapToSource(proxyIndex);
|
||||
|
||||
if(!sourceIndex.isValid())
|
||||
if (!sourceIndex.isValid())
|
||||
return 0;
|
||||
else
|
||||
return sourceIndex.row();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
#include "directorymodel.h"
|
||||
|
||||
DirectoryModel::DirectoryModel()
|
||||
{
|
||||
|
||||
}
|
||||
DirectoryModel::DirectoryModel() {}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "emotelistmodel.h"
|
||||
|
||||
int EmoteListModel::rowCount(const QModelIndex &parent) const {
|
||||
int EmoteListModel::rowCount(const QModelIndex& parent) const {
|
||||
return emotes->size();
|
||||
}
|
||||
|
||||
QVariant EmoteListModel::data(const QModelIndex &index, int role) const {
|
||||
QVariant EmoteListModel::data(const QModelIndex& index, int role) const {
|
||||
if (role == Qt::DisplayRole)
|
||||
return QVariant::fromValue<Emote*>(emotes->at(index.row()));
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "encryption.h"
|
||||
#include <stdlib.h>
|
||||
#include <QDebug>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <QJsonDocument>
|
||||
#include <cstring>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void Encryption::createNewDeviceKeys() {
|
||||
initAccount();
|
||||
|
@ -35,7 +35,6 @@ void Encryption::createNewDeviceKeys() {
|
|||
|
||||
qDebug() << "identity keys: " << (char*)identity_memory;
|
||||
qDebug() << "identity keys (parsed): " << identityKey;
|
||||
|
||||
}
|
||||
|
||||
QString Encryption::saveDeviceKeys() {
|
||||
|
@ -108,11 +107,7 @@ QString Encryption::signMessage(QString message) {
|
|||
|
||||
void* memory = malloc(length);
|
||||
|
||||
olm_account_sign(
|
||||
account,
|
||||
message.data(), message.length(),
|
||||
memory, length
|
||||
);
|
||||
olm_account_sign(account, message.data(), message.length(), memory, length);
|
||||
|
||||
qDebug() << "Signed: " << (char*)memory;
|
||||
|
||||
|
@ -169,8 +164,16 @@ OlmSession* Encryption::beginOutboundOlmSession(std::string identityKey, std::st
|
|||
int fd = open("/dev/random", O_RDONLY);
|
||||
read(fd, memory, length);
|
||||
|
||||
olm_create_outbound_session(outboundSession, account, identityKey.data(), identityKey.length(), oneTimeKey.data(), oneTimeKey.length(), (uint8_t*)memory, length);
|
||||
//qDebug() << "ERR: " << olm_session_last_error(outboundSession);
|
||||
olm_create_outbound_session(
|
||||
outboundSession,
|
||||
account,
|
||||
identityKey.data(),
|
||||
identityKey.length(),
|
||||
oneTimeKey.data(),
|
||||
oneTimeKey.length(),
|
||||
(uint8_t*)memory,
|
||||
length);
|
||||
// qDebug() << "ERR: " << olm_session_last_error(outboundSession);
|
||||
|
||||
return outboundSession;
|
||||
|
||||
|
@ -181,7 +184,6 @@ OlmSession* Encryption::beginOutboundOlmSession(std::string identityKey, std::st
|
|||
void const * their_one_time_key, size_t their_one_time_key_length,
|
||||
void * random, size_t random_length
|
||||
);*/
|
||||
|
||||
}
|
||||
|
||||
std::string Encryption::getSessionId(OlmSession* session) {
|
||||
|
@ -192,10 +194,7 @@ std::string Encryption::getSessionId(OlmSession* session) {
|
|||
/** An identifier for this session. Will be the same for both ends of the
|
||||
* conversation. If the id buffer is too small then olm_session_last_error()
|
||||
* will be "OUTPUT_BUFFER_TOO_SMALL". */
|
||||
olm_session_id(
|
||||
session,
|
||||
memory, length
|
||||
);
|
||||
olm_session_id(session, memory, length);
|
||||
|
||||
return memory;
|
||||
}
|
||||
|
@ -229,7 +228,8 @@ OlmSession* Encryption::createInboundSession(std::string senderKey, std::string
|
|||
void* inboundMemory = malloc(olm_session_size());
|
||||
auto inboundSession = olm_session(inboundMemory);
|
||||
|
||||
olm_create_inbound_session_from(inboundSession, account, (void*)senderKey.c_str(), senderKey.length(), (void*)body.c_str(), body.length());
|
||||
olm_create_inbound_session_from(
|
||||
inboundSession, account, (void*)senderKey.c_str(), senderKey.length(), (void*)body.c_str(), body.length());
|
||||
|
||||
return inboundSession;
|
||||
}
|
||||
|
@ -237,15 +237,15 @@ OlmSession* Encryption::createInboundSession(std::string senderKey, std::string
|
|||
std::vector<std::uint8_t> Encryption::decrypt(OlmSession* session, int msgType, std::string cipherText) {
|
||||
/*std::string maxPlaintextLengthBuffer = cipherText;
|
||||
|
||||
size_t maxPlaintextLength = olm_decrypt_max_plaintext_length(session, msgType, (void*)maxPlaintextLengthBuffer.data(), maxPlaintextLengthBuffer.length());;
|
||||
qDebug() << "THE ERROR YOU ARE LOOKING FOR " << olm_session_last_error(session);
|
||||
if(maxPlaintextLength == olm_error())
|
||||
return "";
|
||||
size_t maxPlaintextLength = olm_decrypt_max_plaintext_length(session, msgType,
|
||||
(void*)maxPlaintextLengthBuffer.data(), maxPlaintextLengthBuffer.length());; qDebug() << "THE ERROR YOU ARE LOOKING
|
||||
FOR " << olm_session_last_error(session); if(maxPlaintextLength == olm_error()) return "";
|
||||
|
||||
char* plaintext = new char[maxPlaintextLength];
|
||||
//plaintext[maxPlaintextLength] = '\0';
|
||||
memset(plaintext, '\0', maxPlaintextLength);
|
||||
int size = olm_decrypt(session, msgType, (void*)cipherText.data(), cipherText.length(), (void*)plaintext, maxPlaintextLength);
|
||||
int size = olm_decrypt(session, msgType, (void*)cipherText.data(), cipherText.length(), (void*)plaintext,
|
||||
maxPlaintextLength);
|
||||
//plaintext[size] = '\0';
|
||||
|
||||
plaintext[size + 1] = '\0';
|
||||
|
@ -257,8 +257,9 @@ std::vector<std::uint8_t> Encryption::decrypt(OlmSession* session, int msgType,
|
|||
std::copy(cipherText.begin(), cipherText.end(), tmp_plaintext_buffer.begin());
|
||||
|
||||
// create the result buffer
|
||||
size_t length = olm_decrypt_max_plaintext_length(session, msgType, tmp_plaintext_buffer.data(), tmp_plaintext_buffer.size());
|
||||
if(length == olm_error())
|
||||
size_t length =
|
||||
olm_decrypt_max_plaintext_length(session, msgType, tmp_plaintext_buffer.data(), tmp_plaintext_buffer.size());
|
||||
if (length == olm_error())
|
||||
return {};
|
||||
|
||||
auto result_buffer = std::vector<std::uint8_t>(length);
|
||||
|
@ -267,8 +268,9 @@ std::vector<std::uint8_t> Encryption::decrypt(OlmSession* session, int msgType,
|
|||
auto tmp_buffer = std::vector<std::uint8_t>(cipherText.size());
|
||||
std::copy(cipherText.begin(), cipherText.end(), tmp_buffer.begin());
|
||||
|
||||
auto size = olm_decrypt(session, msgType, tmp_buffer.data(), tmp_buffer.size(), result_buffer.data(), result_buffer.size());
|
||||
if(size == olm_error())
|
||||
auto size =
|
||||
olm_decrypt(session, msgType, tmp_buffer.data(), tmp_buffer.size(), result_buffer.data(), result_buffer.size());
|
||||
if (size == olm_error())
|
||||
return {};
|
||||
|
||||
auto output = std::vector<std::uint8_t>(size);
|
||||
|
@ -315,8 +317,9 @@ std::vector<std::uint8_t> Encryption::decrypt(OlmInboundGroupSession* session, s
|
|||
std::copy(cipherText.begin(), cipherText.end(), tmp_plaintext_buffer.begin());
|
||||
|
||||
// create the result buffer
|
||||
size_t length = olm_group_decrypt_max_plaintext_length(session, tmp_plaintext_buffer.data(), tmp_plaintext_buffer.size());
|
||||
if(length == olm_error())
|
||||
size_t length =
|
||||
olm_group_decrypt_max_plaintext_length(session, tmp_plaintext_buffer.data(), tmp_plaintext_buffer.size());
|
||||
if (length == olm_error())
|
||||
return {};
|
||||
|
||||
auto result_buffer = std::vector<std::uint8_t>(length);
|
||||
|
@ -326,8 +329,9 @@ std::vector<std::uint8_t> Encryption::decrypt(OlmInboundGroupSession* session, s
|
|||
std::copy(cipherText.begin(), cipherText.end(), tmp_buffer.begin());
|
||||
|
||||
uint32_t msgIndex;
|
||||
auto size = olm_group_decrypt(session, tmp_buffer.data(), tmp_buffer.size(), result_buffer.data(), result_buffer.size(), &msgIndex);
|
||||
if(size == olm_error())
|
||||
auto size = olm_group_decrypt(
|
||||
session, tmp_buffer.data(), tmp_buffer.size(), result_buffer.data(), result_buffer.size(), &msgIndex);
|
||||
if (size == olm_error())
|
||||
return {};
|
||||
|
||||
auto output = std::vector<std::uint8_t>(size);
|
||||
|
|
|
@ -2,33 +2,33 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
#include "room.h"
|
||||
#include "matrixcore.h"
|
||||
#include "room.h"
|
||||
|
||||
EventModel::EventModel(MatrixCore& matrix) : matrix(matrix) {}
|
||||
|
||||
int EventModel::rowCount(const QModelIndex &parent) const {
|
||||
if(!room)
|
||||
int EventModel::rowCount(const QModelIndex& parent) const {
|
||||
if (!room)
|
||||
return 0;
|
||||
|
||||
return room->events.size();
|
||||
}
|
||||
|
||||
QVariant EventModel::data(const QModelIndex &index, int role) const {
|
||||
if(!room || index.row() >= room->events.size())
|
||||
QVariant EventModel::data(const QModelIndex& index, int role) const {
|
||||
if (!room || index.row() >= room->events.size())
|
||||
return "";
|
||||
|
||||
Event* event = room->events[index.row()];
|
||||
|
||||
if(role == Qt::DisplayRole) {
|
||||
if (role == Qt::DisplayRole) {
|
||||
return QVariant::fromValue<Event*>(event);
|
||||
} else if(role == CondenseRole) {
|
||||
if(index.row() + 1 >= room->events.size())
|
||||
} else if (role == CondenseRole) {
|
||||
if (index.row() + 1 >= room->events.size())
|
||||
return false;
|
||||
|
||||
const Event* previousEvent = room->events[index.row() + 1];
|
||||
return previousEvent->getSender() == event->getSender();
|
||||
} else if(role == TimestampRole)
|
||||
} else if (role == TimestampRole)
|
||||
return event->timestamp.toString(Qt::DefaultLocaleShortDate);
|
||||
|
||||
return "";
|
||||
|
@ -48,21 +48,21 @@ void EventModel::setRoom(Room* room) {
|
|||
}
|
||||
|
||||
void EventModel::beginUpdate(const unsigned int num) {
|
||||
if(room)
|
||||
if (room)
|
||||
beginInsertRows(QModelIndex(), 0, num);
|
||||
}
|
||||
|
||||
void EventModel::beginHistory(int size) {
|
||||
if(room)
|
||||
if (room)
|
||||
beginInsertRows(QModelIndex(), room->events.size(), room->events.size() + size);
|
||||
}
|
||||
|
||||
void EventModel::updateEvent(const Event* event) {
|
||||
if(!room)
|
||||
if (!room)
|
||||
return;
|
||||
|
||||
for(size_t i = 0; i < room->events.size(); i++) {
|
||||
if(room->events[i] == event) {
|
||||
for (size_t i = 0; i < room->events.size(); i++) {
|
||||
if (room->events[i] == event) {
|
||||
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
|
||||
return;
|
||||
}
|
||||
|
@ -70,11 +70,11 @@ void EventModel::updateEvent(const Event* event) {
|
|||
}
|
||||
|
||||
void EventModel::updateEventsByMember(const QString& id) {
|
||||
if(!room)
|
||||
if (!room)
|
||||
return;
|
||||
|
||||
for(size_t i = 0; i < room->events.size(); i++) {
|
||||
if(room->events[i]->getSender() == id)
|
||||
for (size_t i = 0; i < room->events.size(); i++) {
|
||||
if (room->events[i]->getSender() == id)
|
||||
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
|
||||
}
|
||||
}
|
||||
|
|
38
src/main.cpp
38
src/main.cpp
|
@ -1,24 +1,24 @@
|
|||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QQmlComponent>
|
||||
#include <QJsonArray>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QMessageBox>
|
||||
#include <QApplication>
|
||||
#include <QGuiApplication>
|
||||
#include <QJsonArray>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlComponent>
|
||||
#include <QQmlContext>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QtQuick/QQuickWindow>
|
||||
#include <QtWebEngine/QtWebEngine>
|
||||
|
||||
#include "eventmodel.h"
|
||||
#include "membermodel.h"
|
||||
#include "matrixcore.h"
|
||||
#include "network.h"
|
||||
#include "desktop.h"
|
||||
#include "roomlistsortmodel.h"
|
||||
#include "emote.h"
|
||||
#include "appcore.h"
|
||||
#include "desktop.h"
|
||||
#include "emote.h"
|
||||
#include "eventmodel.h"
|
||||
#include "matrixcore.h"
|
||||
#include "membermodel.h"
|
||||
#include "network.h"
|
||||
#include "roomlistsortmodel.h"
|
||||
|
||||
void AppCore::addAccount(QString profileName) {
|
||||
accounts.push_back(new MatrixCore(profileName));
|
||||
|
@ -31,8 +31,8 @@ void AppCore::addAccount(QString profileName) {
|
|||
void AppCore::switchAccount(QString profileName) {
|
||||
qDebug() << "switching to " << profileName;
|
||||
|
||||
for(auto account : accounts) {
|
||||
if(account->profileName == profileName) {
|
||||
for (auto account : accounts) {
|
||||
if (account->profileName == profileName) {
|
||||
qDebug() << account->profileName << " = " << profileName;
|
||||
context->setContextProperty("matrix", account);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ void AppCore::switchAccount(QString profileName) {
|
|||
|
||||
QVariantList AppCore::getAccounts() {
|
||||
QVariantList list;
|
||||
for(auto account : accounts)
|
||||
for (auto account : accounts)
|
||||
list.push_back(QVariant::fromValue(account));
|
||||
|
||||
return list;
|
||||
|
@ -86,7 +86,7 @@ int main(int argc, char* argv[]) {
|
|||
AppCore* core = new AppCore();
|
||||
core->context = context;
|
||||
|
||||
if(parser.isSet(profileOption)) {
|
||||
if (parser.isSet(profileOption)) {
|
||||
core->addAccount(parser.value(profileOption));
|
||||
} else {
|
||||
core->addAccount();
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,31 +2,31 @@
|
|||
|
||||
#include "room.h"
|
||||
|
||||
int MemberModel::rowCount(const QModelIndex &parent) const {
|
||||
if(!room)
|
||||
int MemberModel::rowCount(const QModelIndex& parent) const {
|
||||
if (!room)
|
||||
return 0;
|
||||
|
||||
return room->members.size();
|
||||
}
|
||||
|
||||
QVariant MemberModel::data(const QModelIndex &index, int role) const {
|
||||
if(!room)
|
||||
QVariant MemberModel::data(const QModelIndex& index, int role) const {
|
||||
if (!room)
|
||||
return "";
|
||||
|
||||
if(index.row() >= room->members.size())
|
||||
if (index.row() >= room->members.size())
|
||||
return "";
|
||||
|
||||
if(role == DisplayNameRole)
|
||||
if (role == DisplayNameRole)
|
||||
return room->members.at(index.row())->getDisplayName();
|
||||
else if(role == AvatarURLRole)
|
||||
else if (role == AvatarURLRole)
|
||||
return room->members.at(index.row())->getAvatar();
|
||||
else if(role == IdRole)
|
||||
else if (role == IdRole)
|
||||
return room->members.at(index.row())->getId();
|
||||
else {
|
||||
int powerLevel = room->powerLevelList[room->members.at(index.row())->getId()];
|
||||
if(powerLevel == 100)
|
||||
if (powerLevel == 100)
|
||||
return "Admin";
|
||||
else if(powerLevel == 50)
|
||||
else if (powerLevel == 50)
|
||||
return "Moderator";
|
||||
else
|
||||
return "User";
|
||||
|
|
|
@ -4,29 +4,29 @@
|
|||
|
||||
RoomListModel::RoomListModel(QList<Room*>& rooms) : rooms(rooms) {}
|
||||
|
||||
int RoomListModel::rowCount(const QModelIndex &parent) const {
|
||||
int RoomListModel::rowCount(const QModelIndex& parent) const {
|
||||
return rooms.size();
|
||||
}
|
||||
|
||||
QVariant RoomListModel::data(const QModelIndex &index, int role) const {
|
||||
if(role == AliasRole)
|
||||
QVariant RoomListModel::data(const QModelIndex& index, int role) const {
|
||||
if (role == AliasRole)
|
||||
return rooms[index.row()]->getName();
|
||||
else if(role == AvatarRole)
|
||||
else if (role == AvatarRole)
|
||||
return rooms[index.row()]->getAvatar();
|
||||
else if(role == JoinStateRole)
|
||||
else if (role == JoinStateRole)
|
||||
return rooms[index.row()]->getJoinState();
|
||||
else if(role == TopicRole)
|
||||
else if (role == TopicRole)
|
||||
return rooms[index.row()]->getTopic();
|
||||
else if(role == IdRole)
|
||||
else if (role == IdRole)
|
||||
return rooms[index.row()]->getId();
|
||||
else if(role == HighlightCountRole)
|
||||
else if (role == HighlightCountRole)
|
||||
return rooms[index.row()]->getHighlightCount();
|
||||
else if(role == NotificationCountRole)
|
||||
else if (role == NotificationCountRole)
|
||||
return rooms[index.row()]->getNotificationCount();
|
||||
else if(role == DirectRole)
|
||||
else if (role == DirectRole)
|
||||
return rooms[index.row()]->getDirect();
|
||||
else {
|
||||
if(rooms[index.row()]->getDirect())
|
||||
if (rooms[index.row()]->getDirect())
|
||||
return "Direct Chats";
|
||||
else
|
||||
return rooms[index.row()]->getJoinState();
|
||||
|
@ -48,9 +48,9 @@ QHash<int, QByteArray> RoomListModel::roleNames() const {
|
|||
return roles;
|
||||
}
|
||||
|
||||
void RoomListModel::updateRoom(Room *room) {
|
||||
for(unsigned i = 0; i < rooms.size(); i++) {
|
||||
if(room == rooms[i])
|
||||
void RoomListModel::updateRoom(Room* room) {
|
||||
for (unsigned i = 0; i < rooms.size(); i++) {
|
||||
if (room == rooms[i])
|
||||
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#include "roomlistsortmodel.h"
|
||||
|
||||
#include "membermodel.h"
|
||||
#include "room.h"
|
||||
#include "roomlistmodel.h"
|
||||
#include "membermodel.h"
|
||||
|
||||
bool RoomListSortModel::lessThan(const QModelIndex& left, const QModelIndex& right) const {
|
||||
const QString sectionLeft = sourceModel()->data(left, RoomListModel::SectionRole).toString();
|
||||
const QString sectionRight = sourceModel()->data(right, RoomListModel::SectionRole).toString();
|
||||
|
||||
if(sectionRight == "Direct Chats")
|
||||
if (sectionRight == "Direct Chats")
|
||||
return false;
|
||||
|
||||
if(sectionLeft == "Direct Chats")
|
||||
if (sectionLeft == "Direct Chats")
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -21,15 +21,16 @@ bool MemberListSortModel::lessThan(const QModelIndex& left, const QModelIndex& r
|
|||
const QString sectionLeft = sourceModel()->data(left, MemberModel::SectionRole).toString();
|
||||
const QString sectionRight = sourceModel()->data(right, MemberModel::SectionRole).toString();
|
||||
|
||||
if(sectionLeft == "Admin" && sectionRight == "Moderator")
|
||||
if (sectionLeft == "Admin" && sectionRight == "Moderator")
|
||||
return true;
|
||||
else if(sectionLeft == "Moderator" && sectionRight == "User")
|
||||
else if (sectionLeft == "Moderator" && sectionRight == "User")
|
||||
return true;
|
||||
else if(sectionLeft == "Admin" && sectionRight == "User")
|
||||
else if (sectionLeft == "Admin" && sectionRight == "User")
|
||||
return true;
|
||||
|
||||
if(sectionLeft == sectionRight)
|
||||
return sourceModel()->data(left, MemberModel::DisplayNameRole).toString() < sourceModel()->data(right, MemberModel::DisplayNameRole).toString();
|
||||
if (sectionLeft == sectionRight)
|
||||
return sourceModel()->data(left, MemberModel::DisplayNameRole).toString() <
|
||||
sourceModel()->data(right, MemberModel::DisplayNameRole).toString();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Reference in a new issue