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
|
|
@ -7,28 +7,28 @@ set(CMAKE_AUTORCC ON)
|
||||||
find_package(Qt5 COMPONENTS Core Quick Widgets WebEngine REQUIRED)
|
find_package(Qt5 COMPONENTS Core Quick Widgets WebEngine REQUIRED)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
qml.qrc
|
qml.qrc
|
||||||
src/eventmodel.cpp
|
src/eventmodel.cpp
|
||||||
include/eventmodel.h
|
include/eventmodel.h
|
||||||
src/matrixcore.cpp
|
src/matrixcore.cpp
|
||||||
include/matrixcore.h
|
include/matrixcore.h
|
||||||
include/network.h
|
include/network.h
|
||||||
include/requestsender.h
|
include/requestsender.h
|
||||||
include/room.h
|
include/room.h
|
||||||
include/roomlistmodel.h
|
include/roomlistmodel.h
|
||||||
src/roomlistmodel.cpp
|
src/roomlistmodel.cpp
|
||||||
include/desktop.h
|
include/desktop.h
|
||||||
include/membermodel.h
|
include/membermodel.h
|
||||||
src/membermodel.cpp
|
src/membermodel.cpp
|
||||||
src/roomlistsortmodel.cpp
|
src/roomlistsortmodel.cpp
|
||||||
include/roomlistsortmodel.h
|
include/roomlistsortmodel.h
|
||||||
include/emotelistmodel.h
|
include/emotelistmodel.h
|
||||||
src/emotelistmodel.cpp
|
src/emotelistmodel.cpp
|
||||||
include/emote.h
|
include/emote.h
|
||||||
include/appcore.h
|
include/appcore.h
|
||||||
include/encryption.h
|
include/encryption.h
|
||||||
src/encryption.cpp)
|
src/encryption.cpp)
|
||||||
|
|
||||||
find_package(Olm REQUIRED)
|
find_package(Olm REQUIRED)
|
||||||
find_package(cmark REQUIRED)
|
find_package(cmark REQUIRED)
|
||||||
|
|
30
README.md
30
README.md
|
@ -1,6 +1,8 @@
|
||||||
# Trinity
|
# Trinity
|
||||||
A Qt5 QML Matrix client, which supports end-to-end encryption (WIP) and has a Discord-like interface.
|
A Qt5 QML Matrix client, which supports end-to-end encryption (WIP) and has a Discord-like interface.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
* Basic messaging capabilities
|
* Basic messaging capabilities
|
||||||
* Sending and recieving markdown messages, formatting can be disabled
|
* 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
|
* Start direct chats with other members
|
||||||
* Custom emote support
|
* 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
|
* Qt5
|
||||||
* WebEngine is also required
|
* WebEngine is also required
|
||||||
* CMark
|
* CMark
|
||||||
* libolm
|
* 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
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <vector>
|
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class MatrixCore;
|
class MatrixCore;
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QSystemTrayIcon>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
class Desktop : public QObject
|
class Desktop : public QObject {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE void showTrayIcon(const bool shouldHide) {
|
Q_INVOKABLE void showTrayIcon(const bool shouldHide) {
|
||||||
QApplication::setQuitOnLastWindowClosed(shouldHide);
|
QApplication::setQuitOnLastWindowClosed(shouldHide);
|
||||||
|
|
||||||
if(shouldHide)
|
if (shouldHide)
|
||||||
icon->show();
|
icon->show();
|
||||||
else
|
else
|
||||||
icon->hide();
|
icon->hide();
|
||||||
|
@ -21,7 +20,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_INVOKABLE bool isTrayIconEnabled() {
|
Q_INVOKABLE bool isTrayIconEnabled() {
|
||||||
return icon->isVisible();;
|
return icon->isVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSystemTrayIcon* icon;
|
QSystemTrayIcon* icon;
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
#ifndef DIRECTORYMODEL_H
|
#ifndef DIRECTORYMODEL_H
|
||||||
#define DIRECTORYMODEL_H
|
#define DIRECTORYMODEL_H
|
||||||
|
|
||||||
|
class DirectoryModel {
|
||||||
class DirectoryModel
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
DirectoryModel();
|
DirectoryModel();
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,13 +5,12 @@
|
||||||
|
|
||||||
#include "emote.h"
|
#include "emote.h"
|
||||||
|
|
||||||
class EmoteListModel : public QAbstractListModel
|
class EmoteListModel : public QAbstractListModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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) {
|
void setList(QList<Emote*>* emotes) {
|
||||||
this->emotes = emotes;
|
this->emotes = emotes;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
#include <olm/olm.h>
|
#include <olm/olm.h>
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@ class MatrixCore;
|
||||||
struct Room;
|
struct Room;
|
||||||
class Event;
|
class Event;
|
||||||
|
|
||||||
class EventModel : public QAbstractListModel
|
class EventModel : public QAbstractListModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum EventRoles {
|
enum EventRoles {
|
||||||
|
@ -17,21 +16,21 @@ public:
|
||||||
|
|
||||||
EventModel(MatrixCore& matrix);
|
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 beginUpdate(const unsigned int num);
|
||||||
|
|
||||||
void endUpdate() {
|
void endUpdate() {
|
||||||
if(room)
|
if (room)
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void beginHistory(int size);
|
void beginHistory(int size);
|
||||||
|
|
||||||
void endHistory() {
|
void endHistory() {
|
||||||
if(room)
|
if (room)
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QJsonObject>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMap>
|
#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 "emote.h"
|
||||||
#include "emotelistmodel.h"
|
#include "emotelistmodel.h"
|
||||||
#include "encryption.h"
|
#include "encryption.h"
|
||||||
|
#include "eventmodel.h"
|
||||||
|
#include "membermodel.h"
|
||||||
|
#include "room.h"
|
||||||
|
#include "roomlistmodel.h"
|
||||||
|
#include "roomlistsortmodel.h"
|
||||||
|
|
||||||
class Network;
|
class Network;
|
||||||
|
|
||||||
class MatrixCore : public QObject
|
class MatrixCore : public QObject {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString profileName MEMBER profileName CONSTANT)
|
Q_PROPERTY(QString profileName MEMBER profileName CONSTANT)
|
||||||
Q_PROPERTY(bool initialSyncComplete READ isInitialSyncComplete NOTIFY initialSyncFinished)
|
Q_PROPERTY(bool initialSyncComplete READ isInitialSyncComplete NOTIFY initialSyncFinished)
|
||||||
|
@ -39,7 +38,11 @@ public:
|
||||||
Encryption* encryption = nullptr;
|
Encryption* encryption = nullptr;
|
||||||
|
|
||||||
// account
|
// 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 login(const QString& username, const QString& password);
|
||||||
Q_INVOKABLE void logout();
|
Q_INVOKABLE void logout();
|
||||||
|
@ -94,7 +97,14 @@ public:
|
||||||
|
|
||||||
void setMarkdownEnabled(const bool enabled);
|
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;
|
OlmOutboundGroupSession* currentSession = nullptr;
|
||||||
QString currentSessionId, currentSessionKey;
|
QString currentSessionId, currentSessionKey;
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
class Room;
|
class Room;
|
||||||
|
|
||||||
class MemberModel : public QAbstractListModel
|
class MemberModel : public QAbstractListModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum EventRoles {
|
enum EventRoles {
|
||||||
|
@ -15,9 +14,9 @@ public:
|
||||||
SectionRole
|
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) {
|
void beginUpdate(const unsigned int num) {
|
||||||
beginInsertRows(QModelIndex(), 0, num);
|
beginInsertRows(QModelIndex(), 0, num);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "requestsender.h"
|
#include "requestsender.h"
|
||||||
|
@ -17,112 +17,110 @@ public:
|
||||||
QNetworkAccessManager* manager;
|
QNetworkAccessManager* manager;
|
||||||
QString homeserverURL, accessToken;
|
QString homeserverURL, accessToken;
|
||||||
|
|
||||||
template<typename Fn>
|
template<typename Fn> inline void postJSON(const QString& path, const QJsonObject object, Fn&& fn) {
|
||||||
inline void postJSON(const QString& path, const QJsonObject object, Fn&& fn) {
|
QNetworkRequest request(homeserverURL + path);
|
||||||
QNetworkRequest request(homeserverURL + path);
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
|
||||||
|
|
||||||
const QByteArray jsonPost = QJsonDocument(object).toJson();
|
const QByteArray jsonPost = QJsonDocument(object).toJson();
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(jsonPost.size()));
|
request.setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(jsonPost.size()));
|
||||||
|
|
||||||
RequestSender* sender = new RequestSender(manager);
|
RequestSender* sender = new RequestSender(manager);
|
||||||
sender->fn = fn;
|
sender->fn = fn;
|
||||||
|
|
||||||
request.setOriginatingObject(sender);
|
request.setOriginatingObject(sender);
|
||||||
|
|
||||||
QObject::connect(manager, &QNetworkAccessManager::finished, sender, &RequestSender::finished);
|
QObject::connect(manager, &QNetworkAccessManager::finished, sender, &RequestSender::finished);
|
||||||
|
|
||||||
manager->post(request, jsonPost);
|
manager->post(request, jsonPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Fn, typename ProgressFn>
|
template<typename Fn, typename ProgressFn>
|
||||||
inline void postBinary(const QString& path, const QByteArray data, const QString mimeType, Fn&& fn, ProgressFn&& progressFn) {
|
inline void
|
||||||
QNetworkRequest request(homeserverURL + path);
|
postBinary(const QString& path, const QByteArray data, const QString mimeType, Fn&& fn, ProgressFn&& progressFn) {
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, mimeType);
|
QNetworkRequest request(homeserverURL + path);
|
||||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
request.setHeader(QNetworkRequest::ContentTypeHeader, mimeType);
|
||||||
|
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(data.size()));
|
request.setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(data.size()));
|
||||||
|
|
||||||
RequestSender* sender = new RequestSender(manager);
|
RequestSender* sender = new RequestSender(manager);
|
||||||
sender->fn = fn;
|
sender->fn = fn;
|
||||||
|
|
||||||
request.setOriginatingObject(sender);
|
request.setOriginatingObject(sender);
|
||||||
|
|
||||||
QObject::connect(manager, &QNetworkAccessManager::finished, sender, &RequestSender::finished);
|
QObject::connect(manager, &QNetworkAccessManager::finished, sender, &RequestSender::finished);
|
||||||
|
|
||||||
QNetworkReply* reply = manager->post(request, data);
|
QNetworkReply* reply = manager->post(request, data);
|
||||||
QObject::connect(reply, &QNetworkReply::uploadProgress, progressFn);
|
QObject::connect(reply, &QNetworkReply::uploadProgress, progressFn);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Fn>
|
template<typename Fn> inline void post(const QString& path, Fn&& fn) {
|
||||||
inline void post(const QString& path, Fn&& fn) {
|
QNetworkRequest request(homeserverURL + path);
|
||||||
QNetworkRequest request(homeserverURL + path);
|
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
|
||||||
|
|
||||||
RequestSender* sender = new RequestSender(manager);
|
RequestSender* sender = new RequestSender(manager);
|
||||||
sender->fn = fn;
|
sender->fn = fn;
|
||||||
|
|
||||||
request.setOriginatingObject(sender);
|
request.setOriginatingObject(sender);
|
||||||
|
|
||||||
QObject::connect(manager, &QNetworkAccessManager::finished, sender, &RequestSender::finished);
|
QObject::connect(manager, &QNetworkAccessManager::finished, sender, &RequestSender::finished);
|
||||||
|
|
||||||
manager->post(request, QByteArray());
|
manager->post(request, QByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void post(const QString& path) {
|
inline void post(const QString& path) {
|
||||||
QNetworkRequest request(homeserverURL + path);
|
QNetworkRequest request(homeserverURL + path);
|
||||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||||
|
|
||||||
manager->post(request, QByteArray());
|
manager->post(request, QByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void putJSON(const QString& path, const QJsonObject object) {
|
inline void putJSON(const QString& path, const QJsonObject object) {
|
||||||
QNetworkRequest request(homeserverURL + path);
|
QNetworkRequest request(homeserverURL + path);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||||
|
|
||||||
const QByteArray jsonPost = QJsonDocument(object).toJson();
|
const QByteArray jsonPost = QJsonDocument(object).toJson();
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(jsonPost.size()));
|
request.setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(jsonPost.size()));
|
||||||
|
|
||||||
manager->put(request, jsonPost);
|
manager->put(request, jsonPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Fn>
|
template<typename Fn> inline void putJSON(const QString& path, const QJsonObject object, Fn&& fn) {
|
||||||
inline void putJSON(const QString& path, const QJsonObject object, Fn&& fn) {
|
QNetworkRequest request(homeserverURL + path);
|
||||||
QNetworkRequest request(homeserverURL + path);
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
|
||||||
|
|
||||||
RequestSender* sender = new RequestSender(manager);
|
RequestSender* sender = new RequestSender(manager);
|
||||||
sender->fn = fn;
|
sender->fn = fn;
|
||||||
|
|
||||||
request.setOriginatingObject(sender);
|
request.setOriginatingObject(sender);
|
||||||
|
|
||||||
const QByteArray jsonPost = QJsonDocument(object).toJson();
|
const QByteArray jsonPost = QJsonDocument(object).toJson();
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(jsonPost.size()));
|
request.setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(jsonPost.size()));
|
||||||
|
|
||||||
QObject::connect(manager, &QNetworkAccessManager::finished, sender, &RequestSender::finished);
|
QObject::connect(manager, &QNetworkAccessManager::finished, sender, &RequestSender::finished);
|
||||||
|
|
||||||
manager->put(request, jsonPost);
|
manager->put(request, jsonPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Fn>
|
template<typename Fn>
|
||||||
inline void get(const QString& path, Fn&& fn, const QString contentType = "application/json") {
|
inline void get(const QString& path, Fn&& fn, const QString contentType = "application/json") {
|
||||||
QNetworkRequest request(homeserverURL + path);
|
QNetworkRequest request(homeserverURL + path);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
|
request.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
|
||||||
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
request.setRawHeader("Authorization", accessToken.toLocal8Bit());
|
||||||
|
|
||||||
RequestSender* sender = new RequestSender(manager);
|
RequestSender* sender = new RequestSender(manager);
|
||||||
sender->fn = fn;
|
sender->fn = fn;
|
||||||
|
|
||||||
request.setOriginatingObject(sender);
|
request.setOriginatingObject(sender);
|
||||||
|
|
||||||
QObject::connect(manager, &QNetworkAccessManager::finished, sender, &RequestSender::finished);
|
QObject::connect(manager, &QNetworkAccessManager::finished, sender, &RequestSender::finished);
|
||||||
|
|
||||||
manager->get(request);
|
manager->get(request);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
|
#include <QObject>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
class RequestSender : public QObject
|
class RequestSender : public QObject {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
RequestSender(QObject* parent = nullptr) : QObject(parent) {}
|
RequestSender(QObject* parent = nullptr) : QObject(parent) {}
|
||||||
|
@ -22,8 +21,8 @@ public:
|
||||||
std::function<void(QNetworkReply*)> fn;
|
std::function<void(QNetworkReply*)> fn;
|
||||||
|
|
||||||
void finished(QNetworkReply* reply) {
|
void finished(QNetworkReply* reply) {
|
||||||
if(reply->request().originatingObject() == this) {
|
if (reply->request().originatingObject() == this) {
|
||||||
//qDebug() << reply->errorString();
|
// qDebug() << reply->errorString();
|
||||||
|
|
||||||
fn(reply);
|
fn(reply);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QObject>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
class EncryptionInformation : public QObject {
|
class EncryptionInformation : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -12,8 +12,7 @@ public:
|
||||||
QString sessionId;
|
QString sessionId;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Event : public QObject
|
class Event : public QObject {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString sender READ getSender NOTIFY senderChanged)
|
Q_PROPERTY(QString sender READ getSender NOTIFY senderChanged)
|
||||||
Q_PROPERTY(QString msg READ getMsg NOTIFY msgChanged)
|
Q_PROPERTY(QString msg READ getMsg NOTIFY msgChanged)
|
||||||
|
@ -175,8 +174,7 @@ private:
|
||||||
QString id, displayName, avatarURL;
|
QString id, displayName, avatarURL;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Room : public QObject
|
class Room : public QObject {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString id MEMBER id NOTIFY idChanged)
|
Q_PROPERTY(QString id MEMBER id NOTIFY idChanged)
|
||||||
Q_PROPERTY(QString topic MEMBER topic NOTIFY topicChanged)
|
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 highlightCount READ getHighlightCount NOTIFY highlightCountChanged)
|
||||||
Q_PROPERTY(QString notificationCount READ getNotificationCount NOTIFY notificationCountChanged)
|
Q_PROPERTY(QString notificationCount READ getNotificationCount NOTIFY notificationCountChanged)
|
||||||
Q_PROPERTY(bool direct READ getDirect NOTIFY directChanged)
|
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)
|
Q_PROPERTY(bool encrypted READ getEncrypted NOTIFY encryptionChanged)
|
||||||
public:
|
public:
|
||||||
Room(QObject* parent = nullptr) : QObject(parent) {}
|
Room(QObject* parent = nullptr) : QObject(parent) {}
|
||||||
|
@ -255,7 +254,7 @@ public:
|
||||||
void setNotificationLevel(const int level, const bool skipSave = false) {
|
void setNotificationLevel(const int level, const bool skipSave = false) {
|
||||||
notificationLevel = level;
|
notificationLevel = level;
|
||||||
|
|
||||||
if(!skipSave) {
|
if (!skipSave) {
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.beginGroup(id);
|
settings.beginGroup(id);
|
||||||
settings.setValue("notificationLevel", notificationLevel);
|
settings.setValue("notificationLevel", notificationLevel);
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
class Room;
|
class Room;
|
||||||
|
|
||||||
class RoomListModel : public QAbstractListModel
|
class RoomListModel : public QAbstractListModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum EventRoles {
|
enum EventRoles {
|
||||||
|
@ -22,9 +21,9 @@ public:
|
||||||
|
|
||||||
RoomListModel(QList<Room*>& rooms);
|
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() {
|
void beginInsertRoom() {
|
||||||
beginInsertRows(QModelIndex(), rooms.size(), rooms.size());
|
beginInsertRows(QModelIndex(), rooms.size(), rooms.size());
|
||||||
|
|
|
@ -2,37 +2,34 @@
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
class RoomListSortModel : public QSortFilterProxyModel
|
class RoomListSortModel : public QSortFilterProxyModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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 {
|
Q_INVOKABLE unsigned int getOriginalIndex(const unsigned int i) const {
|
||||||
auto const proxyIndex = index(i, 0);
|
auto const proxyIndex = index(i, 0);
|
||||||
auto const sourceIndex = mapToSource(proxyIndex);
|
auto const sourceIndex = mapToSource(proxyIndex);
|
||||||
|
|
||||||
if(!sourceIndex.isValid())
|
if (!sourceIndex.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return sourceIndex.row();
|
return sourceIndex.row();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MemberListSortModel : public QSortFilterProxyModel
|
class MemberListSortModel : public QSortFilterProxyModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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 {
|
Q_INVOKABLE unsigned int getOriginalIndex(const unsigned int i) const {
|
||||||
auto const proxyIndex = index(i, 0);
|
auto const proxyIndex = index(i, 0);
|
||||||
auto const sourceIndex = mapToSource(proxyIndex);
|
auto const sourceIndex = mapToSource(proxyIndex);
|
||||||
|
|
||||||
if(!sourceIndex.isValid())
|
if (!sourceIndex.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return sourceIndex.row();
|
return sourceIndex.row();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#include "directorymodel.h"
|
#include "directorymodel.h"
|
||||||
|
|
||||||
DirectoryModel::DirectoryModel()
|
DirectoryModel::DirectoryModel() {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#include "emotelistmodel.h"
|
#include "emotelistmodel.h"
|
||||||
|
|
||||||
int EmoteListModel::rowCount(const QModelIndex &parent) const {
|
int EmoteListModel::rowCount(const QModelIndex& parent) const {
|
||||||
return emotes->size();
|
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)
|
if (role == Qt::DisplayRole)
|
||||||
return QVariant::fromValue<Emote*>(emotes->at(index.row()));
|
return QVariant::fromValue<Emote*>(emotes->at(index.row()));
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#include "encryption.h"
|
#include "encryption.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
void Encryption::createNewDeviceKeys() {
|
void Encryption::createNewDeviceKeys() {
|
||||||
initAccount();
|
initAccount();
|
||||||
|
@ -35,7 +35,6 @@ void Encryption::createNewDeviceKeys() {
|
||||||
|
|
||||||
qDebug() << "identity keys: " << (char*)identity_memory;
|
qDebug() << "identity keys: " << (char*)identity_memory;
|
||||||
qDebug() << "identity keys (parsed): " << identityKey;
|
qDebug() << "identity keys (parsed): " << identityKey;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Encryption::saveDeviceKeys() {
|
QString Encryption::saveDeviceKeys() {
|
||||||
|
@ -108,11 +107,7 @@ QString Encryption::signMessage(QString message) {
|
||||||
|
|
||||||
void* memory = malloc(length);
|
void* memory = malloc(length);
|
||||||
|
|
||||||
olm_account_sign(
|
olm_account_sign(account, message.data(), message.length(), memory, length);
|
||||||
account,
|
|
||||||
message.data(), message.length(),
|
|
||||||
memory, length
|
|
||||||
);
|
|
||||||
|
|
||||||
qDebug() << "Signed: " << (char*)memory;
|
qDebug() << "Signed: " << (char*)memory;
|
||||||
|
|
||||||
|
@ -169,8 +164,16 @@ OlmSession* Encryption::beginOutboundOlmSession(std::string identityKey, std::st
|
||||||
int fd = open("/dev/random", O_RDONLY);
|
int fd = open("/dev/random", O_RDONLY);
|
||||||
read(fd, memory, length);
|
read(fd, memory, length);
|
||||||
|
|
||||||
olm_create_outbound_session(outboundSession, account, identityKey.data(), identityKey.length(), oneTimeKey.data(), oneTimeKey.length(), (uint8_t*)memory, length);
|
olm_create_outbound_session(
|
||||||
//qDebug() << "ERR: " << olm_session_last_error(outboundSession);
|
outboundSession,
|
||||||
|
account,
|
||||||
|
identityKey.data(),
|
||||||
|
identityKey.length(),
|
||||||
|
oneTimeKey.data(),
|
||||||
|
oneTimeKey.length(),
|
||||||
|
(uint8_t*)memory,
|
||||||
|
length);
|
||||||
|
// qDebug() << "ERR: " << olm_session_last_error(outboundSession);
|
||||||
|
|
||||||
return 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 const * their_one_time_key, size_t their_one_time_key_length,
|
||||||
void * random, size_t random_length
|
void * random, size_t random_length
|
||||||
);*/
|
);*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Encryption::getSessionId(OlmSession* session) {
|
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
|
/** 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()
|
* conversation. If the id buffer is too small then olm_session_last_error()
|
||||||
* will be "OUTPUT_BUFFER_TOO_SMALL". */
|
* will be "OUTPUT_BUFFER_TOO_SMALL". */
|
||||||
olm_session_id(
|
olm_session_id(session, memory, length);
|
||||||
session,
|
|
||||||
memory, length
|
|
||||||
);
|
|
||||||
|
|
||||||
return memory;
|
return memory;
|
||||||
}
|
}
|
||||||
|
@ -229,23 +228,24 @@ OlmSession* Encryption::createInboundSession(std::string senderKey, std::string
|
||||||
void* inboundMemory = malloc(olm_session_size());
|
void* inboundMemory = malloc(olm_session_size());
|
||||||
auto inboundSession = olm_session(inboundMemory);
|
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;
|
return inboundSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::uint8_t> Encryption::decrypt(OlmSession* session, int msgType, std::string cipherText) {
|
std::vector<std::uint8_t> Encryption::decrypt(OlmSession* session, int msgType, std::string cipherText) {
|
||||||
/*std::string maxPlaintextLengthBuffer = cipherText;
|
/*std::string maxPlaintextLengthBuffer = cipherText;
|
||||||
|
|
||||||
size_t maxPlaintextLength = olm_decrypt_max_plaintext_length(session, msgType, (void*)maxPlaintextLengthBuffer.data(), maxPlaintextLengthBuffer.length());;
|
size_t maxPlaintextLength = olm_decrypt_max_plaintext_length(session, msgType,
|
||||||
qDebug() << "THE ERROR YOU ARE LOOKING FOR " << olm_session_last_error(session);
|
(void*)maxPlaintextLengthBuffer.data(), maxPlaintextLengthBuffer.length());; qDebug() << "THE ERROR YOU ARE LOOKING
|
||||||
if(maxPlaintextLength == olm_error())
|
FOR " << olm_session_last_error(session); if(maxPlaintextLength == olm_error()) return "";
|
||||||
return "";
|
|
||||||
|
|
||||||
char* plaintext = new char[maxPlaintextLength];
|
char* plaintext = new char[maxPlaintextLength];
|
||||||
//plaintext[maxPlaintextLength] = '\0';
|
//plaintext[maxPlaintextLength] = '\0';
|
||||||
memset(plaintext, '\0', maxPlaintextLength);
|
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] = '\0';
|
||||||
|
|
||||||
plaintext[size + 1] = '\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());
|
std::copy(cipherText.begin(), cipherText.end(), tmp_plaintext_buffer.begin());
|
||||||
|
|
||||||
// create the result buffer
|
// create the result buffer
|
||||||
size_t length = olm_decrypt_max_plaintext_length(session, msgType, tmp_plaintext_buffer.data(), tmp_plaintext_buffer.size());
|
size_t length =
|
||||||
if(length == olm_error())
|
olm_decrypt_max_plaintext_length(session, msgType, tmp_plaintext_buffer.data(), tmp_plaintext_buffer.size());
|
||||||
|
if (length == olm_error())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto result_buffer = std::vector<std::uint8_t>(length);
|
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());
|
auto tmp_buffer = std::vector<std::uint8_t>(cipherText.size());
|
||||||
std::copy(cipherText.begin(), cipherText.end(), tmp_buffer.begin());
|
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());
|
auto size =
|
||||||
if(size == olm_error())
|
olm_decrypt(session, msgType, tmp_buffer.data(), tmp_buffer.size(), result_buffer.data(), result_buffer.size());
|
||||||
|
if (size == olm_error())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto output = std::vector<std::uint8_t>(size);
|
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());
|
std::copy(cipherText.begin(), cipherText.end(), tmp_plaintext_buffer.begin());
|
||||||
|
|
||||||
// create the result buffer
|
// create the result buffer
|
||||||
size_t length = olm_group_decrypt_max_plaintext_length(session, tmp_plaintext_buffer.data(), tmp_plaintext_buffer.size());
|
size_t length =
|
||||||
if(length == olm_error())
|
olm_group_decrypt_max_plaintext_length(session, tmp_plaintext_buffer.data(), tmp_plaintext_buffer.size());
|
||||||
|
if (length == olm_error())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto result_buffer = std::vector<std::uint8_t>(length);
|
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());
|
std::copy(cipherText.begin(), cipherText.end(), tmp_buffer.begin());
|
||||||
|
|
||||||
uint32_t msgIndex;
|
uint32_t msgIndex;
|
||||||
auto size = olm_group_decrypt(session, tmp_buffer.data(), tmp_buffer.size(), result_buffer.data(), result_buffer.size(), &msgIndex);
|
auto size = olm_group_decrypt(
|
||||||
if(size == olm_error())
|
session, tmp_buffer.data(), tmp_buffer.size(), result_buffer.data(), result_buffer.size(), &msgIndex);
|
||||||
|
if (size == olm_error())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto output = std::vector<std::uint8_t>(size);
|
auto output = std::vector<std::uint8_t>(size);
|
||||||
|
|
|
@ -2,33 +2,33 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "room.h"
|
|
||||||
#include "matrixcore.h"
|
#include "matrixcore.h"
|
||||||
|
#include "room.h"
|
||||||
|
|
||||||
EventModel::EventModel(MatrixCore& matrix) : matrix(matrix) {}
|
EventModel::EventModel(MatrixCore& matrix) : matrix(matrix) {}
|
||||||
|
|
||||||
int EventModel::rowCount(const QModelIndex &parent) const {
|
int EventModel::rowCount(const QModelIndex& parent) const {
|
||||||
if(!room)
|
if (!room)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return room->events.size();
|
return room->events.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant EventModel::data(const QModelIndex &index, int role) const {
|
QVariant EventModel::data(const QModelIndex& index, int role) const {
|
||||||
if(!room || index.row() >= room->events.size())
|
if (!room || index.row() >= room->events.size())
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
Event* event = room->events[index.row()];
|
Event* event = room->events[index.row()];
|
||||||
|
|
||||||
if(role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
return QVariant::fromValue<Event*>(event);
|
return QVariant::fromValue<Event*>(event);
|
||||||
} else if(role == CondenseRole) {
|
} else if (role == CondenseRole) {
|
||||||
if(index.row() + 1 >= room->events.size())
|
if (index.row() + 1 >= room->events.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const Event* previousEvent = room->events[index.row() + 1];
|
const Event* previousEvent = room->events[index.row() + 1];
|
||||||
return previousEvent->getSender() == event->getSender();
|
return previousEvent->getSender() == event->getSender();
|
||||||
} else if(role == TimestampRole)
|
} else if (role == TimestampRole)
|
||||||
return event->timestamp.toString(Qt::DefaultLocaleShortDate);
|
return event->timestamp.toString(Qt::DefaultLocaleShortDate);
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
@ -48,21 +48,21 @@ void EventModel::setRoom(Room* room) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventModel::beginUpdate(const unsigned int num) {
|
void EventModel::beginUpdate(const unsigned int num) {
|
||||||
if(room)
|
if (room)
|
||||||
beginInsertRows(QModelIndex(), 0, num);
|
beginInsertRows(QModelIndex(), 0, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventModel::beginHistory(int size) {
|
void EventModel::beginHistory(int size) {
|
||||||
if(room)
|
if (room)
|
||||||
beginInsertRows(QModelIndex(), room->events.size(), room->events.size() + size);
|
beginInsertRows(QModelIndex(), room->events.size(), room->events.size() + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventModel::updateEvent(const Event* event) {
|
void EventModel::updateEvent(const Event* event) {
|
||||||
if(!room)
|
if (!room)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(size_t i = 0; i < room->events.size(); i++) {
|
for (size_t i = 0; i < room->events.size(); i++) {
|
||||||
if(room->events[i] == event) {
|
if (room->events[i] == event) {
|
||||||
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
|
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -70,11 +70,11 @@ void EventModel::updateEvent(const Event* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventModel::updateEventsByMember(const QString& id) {
|
void EventModel::updateEventsByMember(const QString& id) {
|
||||||
if(!room)
|
if (!room)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(size_t i = 0; i < room->events.size(); i++) {
|
for (size_t i = 0; i < room->events.size(); i++) {
|
||||||
if(room->events[i]->getSender() == id)
|
if (room->events[i]->getSender() == id)
|
||||||
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
|
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
42
src/main.cpp
42
src/main.cpp
|
@ -1,26 +1,26 @@
|
||||||
#include <QGuiApplication>
|
|
||||||
#include <QQmlApplicationEngine>
|
|
||||||
#include <QQmlContext>
|
|
||||||
#include <QQmlComponent>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QMenu>
|
|
||||||
#include <QSystemTrayIcon>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QQmlComponent>
|
||||||
|
#include <QQmlContext>
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
#include <QtQuick/QQuickWindow>
|
#include <QtQuick/QQuickWindow>
|
||||||
#include <QtWebEngine/QtWebEngine>
|
#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 "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) {
|
void AppCore::addAccount(QString profileName) {
|
||||||
accounts.push_back(new MatrixCore(profileName));
|
accounts.push_back(new MatrixCore(profileName));
|
||||||
|
|
||||||
context->setContextProperty("matrix", accounts.back());
|
context->setContextProperty("matrix", accounts.back());
|
||||||
|
@ -28,11 +28,11 @@ void AppCore::addAccount(QString profileName) {
|
||||||
emit accountChange();
|
emit accountChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppCore::switchAccount(QString profileName) {
|
void AppCore::switchAccount(QString profileName) {
|
||||||
qDebug() << "switching to " << profileName;
|
qDebug() << "switching to " << profileName;
|
||||||
|
|
||||||
for(auto account : accounts) {
|
for (auto account : accounts) {
|
||||||
if(account->profileName == profileName) {
|
if (account->profileName == profileName) {
|
||||||
qDebug() << account->profileName << " = " << profileName;
|
qDebug() << account->profileName << " = " << profileName;
|
||||||
context->setContextProperty("matrix", account);
|
context->setContextProperty("matrix", account);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ void AppCore::switchAccount(QString profileName) {
|
||||||
|
|
||||||
QVariantList AppCore::getAccounts() {
|
QVariantList AppCore::getAccounts() {
|
||||||
QVariantList list;
|
QVariantList list;
|
||||||
for(auto account : accounts)
|
for (auto account : accounts)
|
||||||
list.push_back(QVariant::fromValue(account));
|
list.push_back(QVariant::fromValue(account));
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
@ -86,7 +86,7 @@ int main(int argc, char* argv[]) {
|
||||||
AppCore* core = new AppCore();
|
AppCore* core = new AppCore();
|
||||||
core->context = context;
|
core->context = context;
|
||||||
|
|
||||||
if(parser.isSet(profileOption)) {
|
if (parser.isSet(profileOption)) {
|
||||||
core->addAccount(parser.value(profileOption));
|
core->addAccount(parser.value(profileOption));
|
||||||
} else {
|
} else {
|
||||||
core->addAccount();
|
core->addAccount();
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,31 +2,31 @@
|
||||||
|
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
|
||||||
int MemberModel::rowCount(const QModelIndex &parent) const {
|
int MemberModel::rowCount(const QModelIndex& parent) const {
|
||||||
if(!room)
|
if (!room)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return room->members.size();
|
return room->members.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MemberModel::data(const QModelIndex &index, int role) const {
|
QVariant MemberModel::data(const QModelIndex& index, int role) const {
|
||||||
if(!room)
|
if (!room)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
if(index.row() >= room->members.size())
|
if (index.row() >= room->members.size())
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
if(role == DisplayNameRole)
|
if (role == DisplayNameRole)
|
||||||
return room->members.at(index.row())->getDisplayName();
|
return room->members.at(index.row())->getDisplayName();
|
||||||
else if(role == AvatarURLRole)
|
else if (role == AvatarURLRole)
|
||||||
return room->members.at(index.row())->getAvatar();
|
return room->members.at(index.row())->getAvatar();
|
||||||
else if(role == IdRole)
|
else if (role == IdRole)
|
||||||
return room->members.at(index.row())->getId();
|
return room->members.at(index.row())->getId();
|
||||||
else {
|
else {
|
||||||
int powerLevel = room->powerLevelList[room->members.at(index.row())->getId()];
|
int powerLevel = room->powerLevelList[room->members.at(index.row())->getId()];
|
||||||
if(powerLevel == 100)
|
if (powerLevel == 100)
|
||||||
return "Admin";
|
return "Admin";
|
||||||
else if(powerLevel == 50)
|
else if (powerLevel == 50)
|
||||||
return "Moderator";
|
return "Moderator";
|
||||||
else
|
else
|
||||||
return "User";
|
return "User";
|
||||||
|
|
|
@ -4,29 +4,29 @@
|
||||||
|
|
||||||
RoomListModel::RoomListModel(QList<Room*>& rooms) : rooms(rooms) {}
|
RoomListModel::RoomListModel(QList<Room*>& rooms) : rooms(rooms) {}
|
||||||
|
|
||||||
int RoomListModel::rowCount(const QModelIndex &parent) const {
|
int RoomListModel::rowCount(const QModelIndex& parent) const {
|
||||||
return rooms.size();
|
return rooms.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RoomListModel::data(const QModelIndex &index, int role) const {
|
QVariant RoomListModel::data(const QModelIndex& index, int role) const {
|
||||||
if(role == AliasRole)
|
if (role == AliasRole)
|
||||||
return rooms[index.row()]->getName();
|
return rooms[index.row()]->getName();
|
||||||
else if(role == AvatarRole)
|
else if (role == AvatarRole)
|
||||||
return rooms[index.row()]->getAvatar();
|
return rooms[index.row()]->getAvatar();
|
||||||
else if(role == JoinStateRole)
|
else if (role == JoinStateRole)
|
||||||
return rooms[index.row()]->getJoinState();
|
return rooms[index.row()]->getJoinState();
|
||||||
else if(role == TopicRole)
|
else if (role == TopicRole)
|
||||||
return rooms[index.row()]->getTopic();
|
return rooms[index.row()]->getTopic();
|
||||||
else if(role == IdRole)
|
else if (role == IdRole)
|
||||||
return rooms[index.row()]->getId();
|
return rooms[index.row()]->getId();
|
||||||
else if(role == HighlightCountRole)
|
else if (role == HighlightCountRole)
|
||||||
return rooms[index.row()]->getHighlightCount();
|
return rooms[index.row()]->getHighlightCount();
|
||||||
else if(role == NotificationCountRole)
|
else if (role == NotificationCountRole)
|
||||||
return rooms[index.row()]->getNotificationCount();
|
return rooms[index.row()]->getNotificationCount();
|
||||||
else if(role == DirectRole)
|
else if (role == DirectRole)
|
||||||
return rooms[index.row()]->getDirect();
|
return rooms[index.row()]->getDirect();
|
||||||
else {
|
else {
|
||||||
if(rooms[index.row()]->getDirect())
|
if (rooms[index.row()]->getDirect())
|
||||||
return "Direct Chats";
|
return "Direct Chats";
|
||||||
else
|
else
|
||||||
return rooms[index.row()]->getJoinState();
|
return rooms[index.row()]->getJoinState();
|
||||||
|
@ -48,9 +48,9 @@ QHash<int, QByteArray> RoomListModel::roleNames() const {
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomListModel::updateRoom(Room *room) {
|
void RoomListModel::updateRoom(Room* room) {
|
||||||
for(unsigned i = 0; i < rooms.size(); i++) {
|
for (unsigned i = 0; i < rooms.size(); i++) {
|
||||||
if(room == rooms[i])
|
if (room == rooms[i])
|
||||||
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
|
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
#include "roomlistsortmodel.h"
|
#include "roomlistsortmodel.h"
|
||||||
|
|
||||||
|
#include "membermodel.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "roomlistmodel.h"
|
#include "roomlistmodel.h"
|
||||||
#include "membermodel.h"
|
|
||||||
|
|
||||||
bool RoomListSortModel::lessThan(const QModelIndex& left, const QModelIndex& right) const {
|
bool RoomListSortModel::lessThan(const QModelIndex& left, const QModelIndex& right) const {
|
||||||
const QString sectionLeft = sourceModel()->data(left, RoomListModel::SectionRole).toString();
|
const QString sectionLeft = sourceModel()->data(left, RoomListModel::SectionRole).toString();
|
||||||
const QString sectionRight = sourceModel()->data(right, RoomListModel::SectionRole).toString();
|
const QString sectionRight = sourceModel()->data(right, RoomListModel::SectionRole).toString();
|
||||||
|
|
||||||
if(sectionRight == "Direct Chats")
|
if (sectionRight == "Direct Chats")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(sectionLeft == "Direct Chats")
|
if (sectionLeft == "Direct Chats")
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
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 sectionLeft = sourceModel()->data(left, MemberModel::SectionRole).toString();
|
||||||
const QString sectionRight = sourceModel()->data(right, MemberModel::SectionRole).toString();
|
const QString sectionRight = sourceModel()->data(right, MemberModel::SectionRole).toString();
|
||||||
|
|
||||||
if(sectionLeft == "Admin" && sectionRight == "Moderator")
|
if (sectionLeft == "Admin" && sectionRight == "Moderator")
|
||||||
return true;
|
return true;
|
||||||
else if(sectionLeft == "Moderator" && sectionRight == "User")
|
else if (sectionLeft == "Moderator" && sectionRight == "User")
|
||||||
return true;
|
return true;
|
||||||
else if(sectionLeft == "Admin" && sectionRight == "User")
|
else if (sectionLeft == "Admin" && sectionRight == "User")
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(sectionLeft == sectionRight)
|
if (sectionLeft == sectionRight)
|
||||||
return sourceModel()->data(left, MemberModel::DisplayNameRole).toString() < sourceModel()->data(right, MemberModel::DisplayNameRole).toString();
|
return sourceModel()->data(left, MemberModel::DisplayNameRole).toString() <
|
||||||
|
sourceModel()->data(right, MemberModel::DisplayNameRole).toString();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue