Compare commits

..

5 Commits

Author SHA1 Message Date
Tobias Fella
c65183f93a More work 2023-06-14 20:16:05 +02:00
Tobias Fella
39ee17cfa1 ? 2023-06-13 23:32:57 +02:00
Tobias Fella
12bb75e5b0 Fix various problems 2023-06-13 16:28:19 +02:00
Tobias Fella
481f12337a Always start calls with camera disabled
Simplifies the code quite a bit
WIP: Renegotiate to enable camera
2023-06-13 15:45:30 +02:00
Tobias Fella
5e533b8e03 Implement voice & video calls 2023-06-13 15:45:30 +02:00
243 changed files with 26839 additions and 25349 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,4 @@
build*
build
.clang-format
.DS_Store
.kdev4/
@@ -11,4 +11,3 @@ kate.project.ctags.*
.flatpak-builder/
.idea/
cmake-build-*
src/res.generated.qrc

View File

@@ -5,10 +5,10 @@ include:
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/reuse-lint.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/android.yml
# - https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/android-qt6.yml
# - https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux-qt6.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/windows.yml
# - https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/windows-qt6.yml
# - https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/freebsd.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/freebsd.yml
# - https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/freebsd-qt6.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/flatpak.yml

View File

@@ -58,9 +58,5 @@ Dependencies:
'require':
'frameworks/kdbusaddons': '@latest-kf6'
- 'on': ['Linux/Qt6', 'Linux/Qt5']
'require':
'sdk/selenium-webdriver-at-spi': '@latest-kf6'
Options:
require-passing-tests-on: [ 'Linux/Qt5', 'FreeBSD', 'Windows' ]
require-passing-tests-on: [ 'Linux/Qt5', 'FreeBSD' ]

View File

@@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.16)
# KDE Applications version, managed by release script.
set(RELEASE_SERVICE_VERSION_MAJOR "23")
set(RELEASE_SERVICE_VERSION_MINOR "11")
set(RELEASE_SERVICE_VERSION_MINOR "07")
set(RELEASE_SERVICE_VERSION_MICRO "70")
set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}.${RELEASE_SERVICE_VERSION_MICRO}")
@@ -17,7 +17,7 @@ project(NeoChat VERSION ${RELEASE_SERVICE_VERSION})
set(KF_MIN_VERSION "5.105.0")
set(QT_MIN_VERSION "5.15.2")
if (ANDROID)
set(QT_MIN_VERSION "5.15.10")
set(QT_MIN_VERSION "5.15.8")
endif()
find_package(ECM ${KF_MIN_VERSION} REQUIRED NO_MODULE)
@@ -48,30 +48,6 @@ if(NEOCHAT_FLATPAK)
include(cmake/Flatpak.cmake)
endif()
if(QT_MAJOR_VERSION STREQUAL "6")
set(BASICLISTITEM_BOLD "font.bold")
set(OVERLAYSHEET_OPEN "onOpened")
set(QTQUICK_MODULE_QML_VERSION "")
set(QTLOCATION_MODULE_QML_VERSION "")
set(QTMULTIMEDIA_MODULE_QML_VERSION "")
set(QTMULTIMEDIA_AUDIO "MediaPlayer")
# in Audio qt6 we don't have it but we disable it in qt5 => it seems ok
set(QTMULTIMEDIA_AUDIO_AUTOLOAD "")
# In Video qml qt6 we don't have it.
set(QTMULTIMEDIA_VIDEO_FLUSHMODE "")
else()
set(BASICLISTITEM_BOLD "bold")
set(OVERLAYSHEET_OPEN "onSheetOpenChanged")
set(QTQUICK_MODULE_QML_VERSION "2.15")
set(QTLOCATION_MODULE_QML_VERSION "5.15")
set(QTMULTIMEDIA_MODULE_QML_VERSION "5.15")
set(QTMULTIMEDIA_AUDIO "Audio")
set(QTMULTIMEDIA_AUDIO_AUTOLOAD "autoLoad: false")
set(QTMULTIMEDIA_VIDEO_FLUSHMODE "flushMode: VideoOutput.FirstFrame")
endif()
set(QUOTIENT_FORCE_NAMESPACED_INCLUDES TRUE)
ecm_setup_version(${PROJECT_VERSION}
VARIABLE_PREFIX NEOCHAT
VERSION_HEADER ${CMAKE_CURRENT_BINARY_DIR}/neochat-version.h
@@ -93,6 +69,12 @@ set_package_properties(KF${QT_MAJOR_VERSION}Kirigami2 PROPERTIES
)
find_package(KF${QT_MAJOR_VERSION}KirigamiAddons 0.7.2 REQUIRED)
find_package(Qt${QT_MAJOR_VERSION}Keychain)
set_package_properties(Qt${QT_MAJOR_VERSION}Keychain PROPERTIES
TYPE REQUIRED
PURPOSE "Secure storage of account secrets"
)
if(ANDROID)
find_package(OpenSSL)
set_package_properties(OpenSSL PROPERTIES
@@ -116,7 +98,7 @@ if(QT_MAJOR_VERSION STREQUAL "6" AND NOT ANDROID AND NOT WIN32)
set(QUOTIENT_SUFFIX "Qt6")
endif()
find_package(Quotient${QUOTIENT_SUFFIX} 0.7)
find_package(Quotient${QUOTIENT_SUFFIX} 0.6)
set_package_properties(Quotient${QUOTIENT_SUFFIX} PROPERTIES
TYPE REQUIRED
DESCRIPTION "Qt wrapper around Matrix API"
@@ -154,11 +136,23 @@ set_package_properties(KF${QT_MAJOR_VERSION}DocTools PROPERTIES DESCRIPTION
TYPE OPTIONAL
)
if(NOT Quotient${QUOTIENT_SUFFIX}_VERSION_MINOR GREATER 6)
cmake_policy(SET CMP0063 OLD)
endif()
if(ANDROID)
find_package(Sqlite3)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/android/version.gradle.in ${CMAKE_BINARY_DIR}/version.gradle)
endif()
include(FindPkgConfig)
pkg_check_modules(GSTREAMER IMPORTED_TARGET gstreamer-sdp-1.0>1.18 gstreamer-webrtc-1.0>=1.18)
if (TARGET PkgConfig::GSTREAMER)
add_feature_info(voip ON "GStreamer found. Call support is enabled.")
else()
add_feature_info(voip OFF "GStreamer not found. Call support is disabled.")
endif()
ki18n_install(po)
install(FILES org.kde.neochat.desktop DESTINATION ${KDE_INSTALL_APPDIR})
@@ -169,11 +163,9 @@ install(FILES org.kde.neochat.tray.svg DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/h
add_definitions(-DQT_NO_FOREACH)
add_subdirectory(src)
if (BUILD_TESTING)
if (BUILD_TESTING AND Quotient${QUOTIENT_SUFFIX}_VERSION_MINOR GREATER 6)
find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} NO_MODULE COMPONENTS Test)
add_subdirectory(autotests)
add_subdirectory(appiumtests)
endif()
if(KF${QT_MAJOR_VERSION}DocTools_FOUND)
@@ -194,9 +186,3 @@ file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h *.qml)
# Fixes the test by excluding this directory
list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX [[_(install|build)/.*]])
ecm_check_outbound_license(LICENSES GPL-3.0-only FILES ${ALL_SOURCE_FILES})
ecm_qt_install_logging_categories(
EXPORT NEOCHAT
FILE neochat.categories
DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}
)

View File

@@ -47,7 +47,6 @@ android {
compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion
ndkVersion androidNdkVersion
sourceSets {
main {

View File

@@ -1,23 +0,0 @@
# SPDX-License-Identifier: BSD-3-Clause
# SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
if(NOT BUILD_TESTING OR NOT CMAKE_SYSTEM_NAME MATCHES "Linux")
return()
endif()
find_package(SeleniumWebDriverATSPI)
set_package_properties(SeleniumWebDriverATSPI PROPERTIES
DESCRIPTION "Server component for selenium tests using Linux accessibility infrastructure"
PURPOSE "Needed for GUI tests"
URL "https://invent.kde.org/sdk/selenium-webdriver-at-spi"
TYPE OPTIONAL
)
if(NOT SeleniumWebDriverATSPI_FOUND)
return()
endif()
add_test(
NAME logintest
COMMAND selenium-webdriver-at-spi-run ${CMAKE_CURRENT_SOURCE_DIR}/logintest.py
)

View File

@@ -1,42 +0,0 @@
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
from flask import Flask, request, abort
app = Flask(__name__)
@app.route("/_matrix/client/v3/login", methods=["GET"])
def login_get():
result = dict()
result["flows"] = [dict()]
result["flows"][0]["type"] = "m.login.password"
return result
@app.route("/_matrix/client/v3/login", methods=["POST"])
def login_post():
data = request.get_json()
if data["identifier"]["user"] != "user" or data["password"] != "1234":
abort(403)
print(data)
result = dict()
result["access_token"] = "token_1234"
result["device_id"] = "device_1234"
result["user_id"] = "@user:localhost:1234"
return result
@app.route("/_matrix/client/r0/sync")
def sync():
result = dict()
result["next_batch"] = "batch1234"
return result
@app.route("/.well-known/matrix/client")
def well_known():
reply = dict()
reply["m.homeserver"] = dict()
reply["m.homeserver"]["base_url"] = "https://localhost:1234"
return reply
if __name__ == "__main__":
app.run(ssl_context='adhoc', port=1234)

View File

@@ -1,44 +0,0 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org>
# SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
import unittest
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
import time
import subprocess
class LoginTest(unittest.TestCase):
@classmethod
def setUpClass(self):
desired_caps = {}
desired_caps["app"] = "neochat --ignore-ssl-errors"
desired_caps["timeouts"] = {'implicit': 10000}
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723',
desired_capabilities=desired_caps)
subprocess.Popen(["python","login-server.py"])
def setUp(self):
pass
def tearDown(self):
if not self._outcome.result.wasSuccessful():
self.driver.get_screenshot_as_file("failed_test_shot_{}.png".format(self.id()))
@classmethod
def tearDownClass(self):
self.driver.quit()
def test_login(self):
self.driver.find_element(by=AppiumBy.NAME, value="Matrix ID").send_keys("@user:localhost:1234")
self.driver.find_element(by=AppiumBy.NAME, value="Continue").click()
self.driver.find_element(by=AppiumBy.NAME, value="Password").send_keys("1234")
self.driver.find_element(by=AppiumBy.NAME, value="Login").click()
self.driver.find_element(by=AppiumBy.NAME, value="Join some rooms to get started").click()
if __name__ == '__main__':
unittest.main()

View File

@@ -7,9 +7,9 @@
#include "neochatroom.h"
#include <Quotient/connection.h>
#include <Quotient/quotient_common.h>
#include <Quotient/syncdata.h>
#include <connection.h>
#include <quotient_common.h>
#include <syncdata.h>
using namespace Quotient;

View File

@@ -6,9 +6,9 @@
#include "texthandler.h"
#include <Quotient/quotient_common.h>
#include <Quotient/syncdata.h>
#include <qnamespace.h>
#include <quotient_common.h>
#include <syncdata.h>
using namespace Quotient;
@@ -71,6 +71,7 @@ private Q_SLOTS:
void linkPreviewsReject();
};
#ifdef QUOTIENT_07
void TextHandlerTest::initTestCase()
{
connection = Connection::makeMockConnection(QStringLiteral("@bob:kde.org"));
@@ -203,6 +204,7 @@ void TextHandlerTest::initTestCase()
SyncRoomData roomData(QStringLiteral("@bob:kde.org"), JoinState::Join, json.object());
room->update(std::move(roomData));
}
#endif
void TextHandlerTest::allowedAttributes()
{
@@ -477,6 +479,7 @@ void TextHandlerTest::receiveRichtextIn()
QCOMPARE(testTextHandler.handleRecieveRichText(), testOutputString);
}
#ifdef QUOTIENT_07
void TextHandlerTest::receiveRichMxcUrl()
{
const QString testInputString = QStringLiteral(
@@ -494,6 +497,7 @@ void TextHandlerTest::receiveRichMxcUrl()
QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText, room, room->messageEvents().at(0).get()), testOutputString);
}
#endif
/**
* For when your rich input string has a plain text url left in.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

View File

@@ -18,7 +18,6 @@
<name xml:lang="de">NeoChat</name>
<name xml:lang="el">NeoChat</name>
<name xml:lang="en-GB">NeoChat</name>
<name xml:lang="eo">NeoChat</name>
<name xml:lang="es">NeoChat</name>
<name xml:lang="eu">NeoChat</name>
<name xml:lang="fi">NeoChat</name>
@@ -55,7 +54,6 @@
<summary xml:lang="de">Ein Programm für Matrix, das dezentrale Kommunikationsprotokoll</summary>
<summary xml:lang="el">Ένας πελάτης για το Matrix, το αποκεντρωμένο πρωτόκολλο επικοινωνίας</summary>
<summary xml:lang="en-GB">A client for matrix, the decentralised communication protocol</summary>
<summary xml:lang="eo">Kliento por matrix, la malcentra komunikprotokolo</summary>
<summary xml:lang="es">Un cliente para Matrix, el protocolo de comunicaciones descentralizado</summary>
<summary xml:lang="eu">Matrix, deszentralizatutako komunikazio protokolorako bezero bat</summary>
<summary xml:lang="fi">Asiakas Matrixille, hajautetulle viestintäyhteyskäytännölle</summary>
@@ -69,7 +67,7 @@
<summary xml:lang="ka">კლიენტი Matrix-სთვის, დეცენტრალიზებული კომუნიკაციის პროტოკოლისთვის</summary>
<summary xml:lang="ko">Matrix, 분산 대화 프로토콜 클라이언트</summary>
<summary xml:lang="nl">Een client voor matrix, het gedecentraliseerde communicatieprotocol</summary>
<summary xml:lang="nn">Ein klient for Matrix  protokollen for desentralisert kommunikasjon</summary>
<summary xml:lang="nn">Ein klient for Matrix, den desentraliserte lynmeldings­protokollen</summary>
<summary xml:lang="pa">ਮੈਟਰਿਕਸ, ਸਰਬ-ਸਾਂਝੇ ਸੰਚਾਰ ਪਰੋਟੋਕਾਲ, ਲਈ ਕਲਾਈਂਟ ਹੈ</summary>
<summary xml:lang="pl">Program do obsługi matriksa, rozproszonego protokołu porozumiewania się</summary>
<summary xml:lang="pt">Um cliente para o Matrix, o protocolo de comunicação descentralizado</summary>
@@ -90,16 +88,13 @@ to provide a convergent experience across multiple platforms.</p>
<p xml:lang="ca">El NeoChat és un client de Matrix, el protocol descentralitzat de comunicacions de missatgeria instantània. Permet enviar missatges de text, fitxers de vídeo i d'àudio a la família, col·legues i amics. Fa servir els Frameworks de KDE i, sobretot, el Kirigami per a proporcionar una experiència convergent a través de diverses plataformes.</p>
<p xml:lang="ca-valencia">NeoChat és un client de Matrix, el protocol descentralitzat de comunicacions de missatgeria instantània. Permet enviar missatges de text, fitxers de vídeo i d'àudio a la família, col·legues i amics. Utilitza els Frameworks de KDE i, sobretot, Kirigami per a proporcionar una experiència convergent a través de diverses plataformes.</p>
<p xml:lang="en-GB">NeoChat is a client for Matrix, the decentralised communication protocol for instant messaging. It allows you to send text messages, videos and audio files to your family, colleagues and friends. It uses KDE frameworks and most notably Kirigami to provide a convergent experience across multiple platforms.</p>
<p xml:lang="eo">NeoChat estas kliento por Matrix, la malcentra komunikoprotokolo por tuja mesaĝado. Ĝi ebligas al vi sendi tekstmesaĝojn, filmetojn kaj sondosierojn al via familio, kolegoj kaj amikoj. Ĝi uzas KDE-framojn kaj precipe Kirigami por disponigi konverĝan sperton tra pluraj platformoj.</p>
<p xml:lang="es">NeoChat es un cliente para Matrix, el protocolo de comunicaciones descentralizado para mensajería instantánea. Le permite enviar mensajes de texto, vídeos y archivos de sonido a su familia, compañeros de trabajo y amigos. Usa la infraestructura de KDE y, en particular, Kirigami para proporcionar una experiencia convergente en muchas plataformas.</p>
<p xml:lang="fi">NeoChat on asiakassovellus Matrixille, hajautetulle pikaviestinyhteyskäytännölle. Sillä voi lähettää teksti-, video- ja ääniviestejä perheelle, tutuille ja ystäville. Se käyttää KDE-kehystä ja erityisesti Kirigamia tuottaakseen mukautuvan monialustaisen käyttökokemuksen.</p>
<p xml:lang="fr">NeoChat est un client pour le protocole Matrix, un protocole décentralisé de communications pour messagerie instantané. Il vous permet d'envoyer des messages de texte, des vidéos et des fichiers audio à votre famille, vos collègues et vos amis. Il utilise les environnements de développement et plus précisément Kirigami pour fournir une expérience convergente sur plusieurs plate-formes. </p>
<p xml:lang="gl">NeoChat é un cliente para Matrix, o protocolo de comunicación descentralizada para mensaxería instantánea. Podes enviar mensaxes de texto, vídeos e ficheiros de son á túa familia, colegas e amizades. Usas infraestruturas de KDE e principalmente Kirigami para proporcionar unha experiencia de uso converxente para varias plataformas.</p>
<p xml:lang="ia">NeoChat es un cliente per Matrix, le protocollo de communication decentralisate per messager instantanee. Illo te permitte inviar messager de texto, files de video e audio a tu familia, collegas e amicos usante. Illo usa KDE frameworks e super toto Kirigamii forni un experientia convergente trans platteforme multiple.</p>
<p xml:lang="it">NeoChat è un client per Matrix, il protocollo di comunicazione decentralizzato per la messaggistica istantanea. Ti consente di inviare messaggi di testo, video e file audio a familiari, colleghi e amici. Utilizza i framework KDE e in particolare Kirigami per fornire un'esperienza convergente su più piattaforme.</p>
<p xml:lang="ka">NeoChat არის Matrix კლიენტი. ის საშუალებას გაძლევთ გაგზავნოთ ტექსტური შეტყობინებები, ვიდეოები და აუდიო ფაილები თქვენს ოჯახს, კოლეგებსა და მეგობრებს მატრიქსის პროტოკოლის გამოყენებით.</p>
<p xml:lang="nl">NeoChat is een client voor Matrix, het gedecentraliseerde communicatieprotocol voor instant messages. Het biedt u het verzenden van tekstberichten, video's en geluidsbestanden naar uw familie, collega's en vrienden. Het gebruik KDE frameworks en het meest opmerkelijk Kirigami om een convergente ervaring te leveren op meerdere platforms.</p>
<p xml:lang="nn">NeoChat er ein klient for Matrix, ein protokoll for desentralisert kommunikasjon. Du kan utveksla tekst, lyd og videoar med kollegaar, vennar og familie. Programmet brukar KDE Frameworks og Kirigami for å gje ei brukarflate tilpassa ulike plattformer.</p>
<p xml:lang="pl">NeoChat jest programem do Matriksa, protokołu rozproszonego porozumiewania się w czasie rzeczywistym. Umożliwia wysyłanie wiadomości tekstowych, filmów oraz dźwięku do twojej rodziny, znajomych oraz przyjaciół. Używa szkieletów KDE i głównie Kirigami, aby zapewnić spójne wrażenia na wielu platformach</p>
<p xml:lang="pt">O NeoChat é um cliente do Matrix. O mesmo permite-lhe enviar mensagens de texto, ficheiros de vídeo e áudio para a sua família, colegas e amigos com o protocolo Matrix. Usa as plataformas do KDE, e principalmente o Kirigami, para oferecer uma experiência convergente entre várias plataformas.</p>
<p xml:lang="sl">Neochat je odjemalec za Matrix, decentralizirani komunikacijski protokol za takojšnje sporočanje. Omogoča vam pošiljanje besedilnih sporočil, videoposnetkov in zvočnih datotek svoji družini, sodelavcem in prijateljem. Uporablja okvire ogrodje KDE frameworks in predvsem Kirigami za zagotavljanje konvergentne izkušnje na več platformah.</p>
@@ -112,14 +107,12 @@ to provide a convergent experience across multiple platforms.</p>
<p xml:lang="ca-valencia">NeoChat pretén ser una aplicació amb totes les característiques per a l'especificació de Matrix. Com a tal, s'ha implementat tota l'especificació actual estable amb les notables excepcions de VoIP, fils i alguns aspectes de l'encriptació d'extrem a extrem. Hi ha algunes altres omissions més xicotetes a causa del fet que l'especificació de Matrix està evolucionant constantment, però l'objectiu seguix sent proporcionar suport eventual per a tota l'especificació.</p>
<p xml:lang="en-GB">NeoChat aims to be a fully featured application for the Matrix specification. As such everything in the current stable specification with the notable exceptions of VoIP, threads and some aspects of End-to-End Encryption are supported. There are a few other smaller omissions due to the fact that the Matrix spec is constantly evolving but the aim remains to provide eventual support for the entire spec.</p>
<p xml:lang="es">NeoChat pretende ser una aplicación con todas las funciones para la especificación de Matrix. Como tal, admite todo en la especificación estable actual, con las notables excepciones de VoIP, subprocesos y algunas funciones de cifrado de extremo a extremo. Existen algunas omisiones menos importantes debido al hecho de que la especificación de Matrix está en constante evolución, pero el objetivo sigue siendo brindar compatibilidad final con toda la especificación.</p>
<p xml:lang="fi">NeoChat pyrkii olemaan Matrix-määritelmän täysominaisuuksinen sovellus, joten se tukee kaikkea nykyisessä vakaassa määritelmässä muutamaa huomattavaa poikkeusta lukuun ottamatta (VoIP, säikeet ja jotkin piirteet päästä päähän -salauksessa). Joitakin pienempiäkin puutteita on Matrix-määritelmän jatkuvan kehityksen vuoksi, mutta lopputavoitteena on tarjota määritelmän täysi tuki.</p>
<p xml:lang="fr">L'objectif de NeoChat est d'être une application complète pour le protocole Matrix. En tant que tel, tout dans la spécification stable actuelle avec les exceptions notables de VoIP, les processus et certains aspects du chiffrement de bout en bout sont pris en charge. Il y a quelques autres petites omissions en raison du fait que la spécification du protocole Matrix est en constante évolution. Cependant, l'objectif reste de fournir un soutien éventuel pour l'ensemble de la spécification.</p>
<p xml:lang="gl">NeoChat pretende ser unha aplicación completa para a especificación de Matrix. Coas excepcións de VoIP, conversas fiadas e algúns aspectos da cifraxe de extremo a extremo, a versión estábel segue as especificacións. Existen algunhas outras pequenas omisións debido ao feito de que Matrix está en continua evolución pero a intención é implementar a especificación completa.</p>
<p xml:lang="ia">NeoChat aspira a esser un application plenemente eminente per le specification de Matrix. Tal como omne cosas in le specification currentemente stabile con le exceptiones notabile de VOIP, threads e alcun aspectos del cryptation End-to-End es supportate. Il ha ltere pauc omissiones, debite al facto que le specification de Matrix es in evolution constante ma le aspiration remane a fornir supporto eventual per le integre specification.</p>
<p xml:lang="it">NeoChat mira ad essere un'applicazione completa per le specifiche Matrix. Pertanto, sono supportati tutti gli elementi dell'attuale specifica stabile con le notevoli eccezioni di VoIP, conversazioni e alcuni aspetti della cifratura end-to-end. Ci sono alcune altre piccole omissioni dovute al fatto che le specifiche Matrix sono in continua evoluzione, ma l'obiettivo rimane quello di fornire un eventuale supporto per l'intera specifica.</p>
<p xml:lang="ka">NeoChat-ი მიზნად ისახავს Matrix სპეციფიკაციის სრული განხორციელება ჰქონდეს. როგორც ასეთი, ყველაფერი მიმდინარე სპეციფიკაციიდან, VoIP-ის, ძაფებისა და გამჭოლი დაშიფვრის ზოგიერთი ასპექტის გარდა, მხარდაჭერილია. შეძლება ასევე იყოს მცირე ლაფსუსებიც იმის გამო, რომ Matrix-ის სპეციფიკაცია მუდმივად ვითარგდება, მაგრამ ჩვენი მიზანი მისი სრული მხარდაჭერაა.</p>
<p xml:lang="nl">NeoChat richt zich op het volledig bieden van alle mogelijkheden van de Matrix-specificatie. Alles in de huidige stabiele specificatie met merkbare uitzondering van VoIP, gekoppelde discussies en sommige aspecten van eind-tot-eind versleuteling worden ondersteund. Er zijn een paar andere kleinere omissies vanwege het feit dat de Matrix specificatie constant evolueert maar het doel blijft het eventueel bieden van ondersteuning van de gehele specificatie.</p>
<p xml:lang="nn">NeoChat har som mål å støtta all funksjonalitet i Matrix-spesifikasjonen. Førebels er alt i den gjeldande stabile spesifikasjonen støtta, med unntak av VoIP, trådar og nokre delar av ende-til-kryptering. Det finst òg andre småting som ikkje er støtta, sidan Matrix-spesifikasjon er i stadig endring, men målet er altså støtte for alt.</p>
<p xml:lang="pl">NeoChat w zamyśle ma być pełnowartościową aplikacją wg wytycznych Matriksa. Z tego powodu, wszystko, co jest obecnie w stabilnych wytycznych z pominięciem VoIP, wątków i niektórych części szyfrowania Użytkownik-do-Użytkownika są obecnie obsługiwane. Pominięto też kilka mniejszych rzeczy ze względu na ciągły rozwój wytycznych Matriksa, lecz celem nadal jest zapewnienie obsługi wszystkich wytycznych.</p>
<p xml:lang="pt">O NeoChat pretende ser uma aplicação completa para a especificação do Matrix. Como tal, tudo o que existe na especificação estável actual, com as notáveis excepções do VoIP, tópicos e alguns aspectos da Encriptação Ponto-a-Ponto, são suportados. Existem mais algumas omissões, devido ao facto que a norma do Matrix está em constante evolução, mas o objectivo continua a ser oferecer o suporte eventual para a norma por inteiro.</p>
<p xml:lang="sl">Neochat cilja, da bi bila popolna aplikacija po specifikaciji Matrixa. Kot takšna vsebuje vse v trenutni stabilni specifikaciji z pomembnimi izjemami pri VoIP, nitih in nekaterih vidikov šifriranja od konca do konca. Obstaja nekaj drugih manjših opustitev zaradi dejstva, da se specifikacija Matrix nenehno razvija, vendar cilj ostaja zagotoviti morebitno podporo celotni specifikaciji.</p>
@@ -132,14 +125,12 @@ to provide a convergent experience across multiple platforms.</p>
<p xml:lang="ca-valencia">A causa de la naturalea del desenvolupament de l'especificació de Matrix, NeoChat també implementa nombroses característiques inestables. Actualment són:</p>
<p xml:lang="en-GB">Due to the nature of the Matrix specification development NeoChat also supports numerous unstable features. Currently these are:</p>
<p xml:lang="es">Debido a la naturaleza del desarrollo de la especificación de Matrix, NeoChat también permite numerosas funciones no estables, como:</p>
<p xml:lang="fi">Matrix-määritelmän kehittyessä NeoChat tukee myös monia epävakaita ominaisuuksia. Tällä hetkellä näitä ovat:</p>
<p xml:lang="fr">En raison de la nature du développement des spécifications du protocole Matrix, NeoChat prend également en charge de nombreuses fonctionnalités instables. Actuellement, ce sont :</p>
<p xml:lang="gl">Debido á natureza do desenvolvemento da especificación de Matrix, NeoChat tamén inclúe varias funcionalidades non estábeis:</p>
<p xml:lang="ia">Debite al natura del disveloppamento de specification de Matrix NeoChat tamben supporta numerose characteristicas instabile. Currentemente istes es:</p>
<p xml:lang="it">A causa della natura dello sviluppo delle specifiche Matrix, NeoChat supporta anche numerose funzionalità instabili. Attualmente queste sono:</p>
<p xml:lang="ka">Matrix-ის სპეციფიკაციის განვითარების ბუნების გამო NeoChat-ს ასევე აქვს უამრავი არასტაბილური ფუნქციაც. ახლა ისინია:</p>
<p xml:lang="nl">Vanwege de aard van de ontwikkeling van de Matrix specificatie ondersteunt NeoChat ook talloze onstabiele mogelijkheden. Dit zijn nu:</p>
<p xml:lang="nn">På grunn av måten Matrix-spesifikasjonen vert utvikla på, støttar NeoChat òg nokre uferdige funksjonar:</p>
<p xml:lang="pl">Ze względu na sposób rozwoju Matriksa, NeoChat obsługuje także kilka niestabilnych możliwości. Obecnie są to:</p>
<p xml:lang="pt">Devido à natureza do desenvolvimento da especificação do Matrix, o NeoChat também suporta diversas funcionalidades instáveis. De momento são:</p>
<p xml:lang="sl">Zaradi narave razvoja specifikacije Matrixa NeoChat podpira tudi številne nestabilne zmožnosti. Trenutno so to:</p>
@@ -153,14 +144,12 @@ to provide a convergent experience across multiple platforms.</p>
<li xml:lang="ca-valencia">Enquestes - MSC3381</li>
<li xml:lang="en-GB">Polls - MSC3381</li>
<li xml:lang="es">Encuestas - MSC3381</li>
<li xml:lang="fi">Kyselyt MSC3381</li>
<li xml:lang="fr">Sondages - MSC3381</li>
<li xml:lang="gl">Enquisas - MSC3381</li>
<li xml:lang="ia">Inquestas - MSC3381</li>
<li xml:lang="it">Sondaggi - MSC3381</li>
<li xml:lang="ka">Polls - MSC3381</li>
<li xml:lang="nl">Polls - MSC3381</li>
<li xml:lang="nn">Avstemmingar  MSC3381</li>
<li xml:lang="pt">Inquéritos - MSC3381</li>
<li xml:lang="sl">Polls - MSC3381</li>
<li xml:lang="ta">வாக்கெடுப்புகள் - MSC3381</li>
@@ -173,14 +162,12 @@ to provide a convergent experience across multiple platforms.</p>
<li xml:lang="ca-valencia">Paquets d'adhesius - MSC2545</li>
<li xml:lang="en-GB">Sticker Packs - MSC2545</li>
<li xml:lang="es">Paquetes de pegatinas - MSC2545</li>
<li xml:lang="fi">Tarrapakkaukset MSC2545</li>
<li xml:lang="fr">Paquets d'auto-collants - MSC2545</li>
<li xml:lang="gl">Paquetes de adhesivos - MSC2545</li>
<li xml:lang="ia">Etiquetta gummate (sticker) -MSC2545</li>
<li xml:lang="it">Pacchetti di adesivi - MSC2545</li>
<li xml:lang="ka">სტიკერების პაკეტები - MSC2545</li>
<li xml:lang="nl">Sticker Packs - MSC2545</li>
<li xml:lang="nn">Klistremerke-pakkar  MSC2545</li>
<li xml:lang="pt">Pacotes de Autocolantes - MSC2545</li>
<li xml:lang="sl">Sticker Packs - MSC2545</li>
<li xml:lang="ta">ஒட்டி தொகுப்புகள் - MSC2545</li>
@@ -193,14 +180,12 @@ to provide a convergent experience across multiple platforms.</p>
<li xml:lang="ca-valencia">Esdeveniments d'ubicació - MSC3488</li>
<li xml:lang="en-GB">Location Events - MSC3488</li>
<li xml:lang="es">Eventos de ubicación - MSC3488</li>
<li xml:lang="fi">Sijaintitapahtumat MSC3488</li>
<li xml:lang="fr">Événements de lieu - MSC3488</li>
<li xml:lang="gl">Localización de eventos - MSC3488</li>
<li xml:lang="ia">Eventos de Location - MSC3488</li>
<li xml:lang="it">Località eventi - MSC3488</li>
<li xml:lang="ka">მდებარეობის მოვლენები - MSC3488</li>
<li xml:lang="nl">Locatie gebeurtenissen - MSC3488</li>
<li xml:lang="nn">Posisjonshendingar  MSC3488</li>
<li xml:lang="pt">Eventos com Localizações - MSC3488</li>
<li xml:lang="sl">Location Events - MSC3488</li>
<li xml:lang="ta">இட நிகழ்வுகள் - MSC3488</li>
@@ -223,7 +208,6 @@ to provide a convergent experience across multiple platforms.</p>
<developer_name xml:lang="de">Die KDE-Gemeinschaft</developer_name>
<developer_name xml:lang="el">Η Κοινότητα του KDE</developer_name>
<developer_name xml:lang="en-GB">The KDE Community</developer_name>
<developer_name xml:lang="eo">La KDE-Komunumo</developer_name>
<developer_name xml:lang="es">La comunidad KDE</developer_name>
<developer_name xml:lang="eu">KDE komunitatea</developer_name>
<developer_name xml:lang="fi">KDE-yhteisö</developer_name>
@@ -257,38 +241,6 @@ to provide a convergent experience across multiple platforms.</p>
<value key="KDE::matrix">#neochat:kde.org</value>
<value key="KDE::windows_store">https://www.microsoft.com/store/apps/9PNXWVNRC29H</value>
<value key="KDE::mastodon">https://kde.social/@neochat</value>
<value key="KDE::windows_store::StoreLogo9x16">https://invent.kde.org/network/neochat/-/raw/master/icons/windows/storelogo-720x1080.png</value>
<value key="KDE::windows_store::StoreLogoSquare">https://invent.kde.org/network/neochat/-/raw/master/icons/windows/storelogo-1080x1080.png</value>
<value key="KDE::windows_store::Icon">https://invent.kde.org/network/neochat/-/raw/master/icons/300-apps-neochat.png</value>
<value key="KDE::windows_store::PromotionalArt16x9">https://invent.kde.org/network/neochat/-/raw/master/icons/windows/promoimage-1920x1080.png</value>
<value key="KDE::windows_store::screenshots::1::image">https://cdn.kde.org/screenshots/neochat/NeoChat-Windows-Timeline.png</value>
<value key="KDE::windows_store::screenshots::1::caption">Main view with room list, chat, and room information</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="ca">Vista principal amb la llista de sales, xats i informació de les sales</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="ca-valencia">Vista principal amb la llista de sales, xats i informació de les sales</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="es">Vista principal con la lista de salas, chat e información de la sala</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="fr">Vue principale avec la liste des salons ainsi que des informations sur les salons et forums de discussions</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="ka">მთავარი ხედი სურათების სიით, ჩატით და ოთახის ინფორმაციით</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="nl">Hoofdweergave met lijst met rooms, chat en roominformatie</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="pt">A área principal com a lista de salas e com informações sobre a conversa e a sala</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="sl">Glavni pogled s seznamom sob, klepetom in informacijami o sobah</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="ta">அரங்குப்பட்டியல், உரையாடல், மற்றும் அரங்குவிவரங்களைக் கொண்டுள்ள பிரதான காட்சி</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="tr">Oda listesini, sohbet penceresini ve oda bilgisini gösteren ana görünüm</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="uk">Головна панель із списком кімнат, спілкуванням та даними щодо кімнати</value>
<value key="KDE::windows_store::screenshots::1::caption" xml:lang="x-test">xxMain view with room list, chat, and room informationxx</value>
<value key="KDE::windows_store::screenshots::2::image">https://cdn.kde.org/screenshots/neochat/NeoChat-Windows-Login.png</value>
<value key="KDE::windows_store::screenshots::2::caption">Login screen</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="ca">Pantalla d'inici de sessió</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="ca-valencia">Pantalla d'inici de sessió</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="es">Pantalla de inicio de sesión</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="fr">Écran de connexion</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="ka">შესვლის ეკრანი</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="nl">Aanmeldscherm</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="pt">Ecrã de autenticação</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="sl">Prijavni zaslon</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="ta">நுழைவுத் திரை</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="tr">Oturum açma ekranı</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="uk">Вікно входу</value>
<value key="KDE::windows_store::screenshots::2::caption" xml:lang="x-test">xxLogin screenxx</value>
</custom>
<launchable type="desktop-id">org.kde.neochat.desktop</launchable>
<screenshots>
@@ -303,7 +255,6 @@ to provide a convergent experience across multiple platforms.</p>
<content_attribute id="social-chat">intense</content_attribute>
</content_rating>
<releases>
<release version="23.04.3" date="2023-07-06"/>
<release version="23.04.2" date="2023-06-08"/>
<release version="23.04.1" date="2023-05-11"/>
<release version="23.04.0" date="2023-04-20">

View File

@@ -11,7 +11,6 @@ Name[cs]=NeoChat
Name[de]=NeoChat
Name[el]=NeoChat
Name[en_GB]=NeoChat
Name[eo]=NeoChat
Name[es]=NeoChat
Name[eu]=NeoChat
Name[fi]=NeoChat
@@ -50,7 +49,6 @@ GenericName[cs]=Klient protokolu Matrix
GenericName[de]=Matrix-Programm
GenericName[el]=Εφαρμογή του Matrix
GenericName[en_GB]=Matrix Client
GenericName[eo]=Matrix-Kliento
GenericName[es]=Cliente para Matrix
GenericName[eu]=Matrix bezeroa
GenericName[fi]=Matrix-asiakas
@@ -88,7 +86,6 @@ Comment[ca@valencia]=Client per al protocol Matrix
Comment[de]=Programm für das Matrix-Protokoll
Comment[el]=Πελάτης για το πρωτόκολλο Matrix
Comment[en_GB]=Client for the Matrix protocol
Comment[eo]=Kliento por la Matrix-protokolo
Comment[es]=Cliente para el protocolo Matrix
Comment[eu]=Matrix protokolorako bezeroa
Comment[fi]=Asiakas Matrix-yhteyskäytännölle
@@ -103,7 +100,7 @@ Comment[ka]=კლიენტი Matrix-ის პროტოკოლის
Comment[ko]=Matrix 프로토콜용 클라이언트
Comment[lt]=Matrix protokolo kliento programa
Comment[nl]=Client voor het Matrix-protocol
Comment[nn]=Klient for Matrix-protokollen
Comment[nn]=Lynmeldings­klient for Matrix-protokollen
Comment[pa]=ਮੈਟਰਿਕਸ ਪਰੋਟੋਕਾਲ ਲਈ ਕਲਾਈਂਟ ਹੈ
Comment[pl]=Program obsługi protokołu Matriksa
Comment[pt]=Cliente para o protocolo Matrix

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -3,144 +3,77 @@
# SPDX-FileCopyrightText: 2020-2021 Tobias Fella <tobias.fella@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
configure_file(qml/Page/RoomList/RoomDelegate.qml ${CMAKE_CURRENT_BINARY_DIR}/qml/Page/RoomList/RoomDelegate.qml)
configure_file(qml/Component/QuickSwitcher.qml ${CMAKE_CURRENT_BINARY_DIR}/qml/Component/QuickSwitcher.qml)
configure_file(qml/Dialog/UserDetailDialog.qml ${CMAKE_CURRENT_BINARY_DIR}/qml/Dialog/UserDetailDialog.qml)
configure_file(qml/Dialog/PowerLevelDialog.qml ${CMAKE_CURRENT_BINARY_DIR}/qml/Dialog/PowerLevelDialog.qml)
configure_file(qml/Component/Timeline/AudioDelegate.qml ${CMAKE_CURRENT_BINARY_DIR}/qml/Component/Timeline/AudioDelegate.qml)
configure_file(qml/Component/Timeline/VideoDelegate.qml ${CMAKE_CURRENT_BINARY_DIR}/qml/Component/Timeline/VideoDelegate.qml)
configure_file(qml/Component/Timeline/OsmLocationPlugin.qml ${CMAKE_CURRENT_BINARY_DIR}/qml/Component/Timeline/OsmLocationPlugin.qml)
configure_file(res.qrc ${CMAKE_CURRENT_SOURCE_DIR}/res.generated.qrc)
add_library(neochat STATIC
controller.cpp
controller.h
actionshandler.cpp
actionshandler.h
models/emojimodel.cpp
models/emojimodel.h
emojitones.cpp
emojitones.h
models/customemojimodel.cpp
models/customemojimodel.h
clipboard.cpp
clipboard.h
matriximageprovider.cpp
matriximageprovider.h
models/messageeventmodel.cpp
models/messageeventmodel.h
models/messagefiltermodel.cpp
models/messagefiltermodel.h
models/roomlistmodel.cpp
models/roomlistmodel.h
models/sortfilterspacelistmodel.cpp
models/sortfilterspacelistmodel.h
models/accountemoticonmodel.cpp
models/accountemoticonmodel.h
spacehierarchycache.cpp
spacehierarchycache.h
roommanager.cpp
roommanager.h
neochatroom.cpp
neochatroom.h
neochatuser.cpp
neochatuser.h
models/userlistmodel.cpp
models/userlistmodel.h
models/userfiltermodel.cpp
models/userfiltermodel.h
models/publicroomlistmodel.cpp
models/publicroomlistmodel.h
models/userdirectorylistmodel.cpp
models/userdirectorylistmodel.h
models/pushrulemodel.cpp
models/pushrulemodel.h
models/keywordnotificationrulemodel.cpp
models/emoticonfiltermodel.cpp
models/emoticonfiltermodel.h
notificationsmanager.cpp
notificationsmanager.h
models/sortfilterroomlistmodel.cpp
models/sortfilterroomlistmodel.h
chatdocumenthandler.cpp
chatdocumenthandler.h
models/devicesmodel.cpp
models/devicesmodel.h
models/devicesproxymodel.cpp
filetypesingleton.cpp
filetypesingleton.h
login.cpp
login.h
models/webshortcutmodel.cpp
models/webshortcutmodel.h
blurhash.cpp
blurhash.h
blurhashimageprovider.cpp
blurhashimageprovider.h
models/collapsestateproxymodel.cpp
models/collapsestateproxymodel.h
models/mediamessagefiltermodel.cpp
models/mediamessagefiltermodel.h
urlhelper.cpp
urlhelper.h
windowcontroller.cpp
windowcontroller.h
linkpreviewer.cpp
linkpreviewer.h
models/completionmodel.cpp
models/completionmodel.h
models/completionproxymodel.cpp
models/completionproxymodel.h
models/actionsmodel.cpp
models/actionsmodel.h
models/serverlistmodel.cpp
models/serverlistmodel.h
models/statemodel.cpp
models/statemodel.h
models/statefiltermodel.cpp
models/statefiltermodel.h
filetransferpseudojob.cpp
filetransferpseudojob.h
models/searchmodel.cpp
models/searchmodel.h
texthandler.cpp
texthandler.h
logger.cpp
logger.h
models/stickermodel.cpp
models/stickermodel.h
models/imagepacksmodel.cpp
models/imagepacksmodel.h
events/imagepackevent.cpp
events/imagepackevent.h
events/joinrulesevent.cpp
events/joinrulesevent.h
events/stickerevent.cpp
models/reactionmodel.cpp
models/reactionmodel.h
delegatesizehelper.cpp
delegatesizehelper.h
models/livelocationsmodel.cpp
models/livelocationsmodel.h
models/locationsmodel.cpp
models/locationsmodel.h
locationhelper.cpp
locationhelper.h
events/pollevent.cpp
pollhandler.cpp
)
ecm_qt_declare_logging_category(neochat
HEADER "messageeventmodel_logging.h"
IDENTIFIER "MessageEvent"
CATEGORY_NAME "org.kde.neochat.messageeventmodel"
DESCRIPTION "Neochat: messageeventmodel"
DEFAULT_SEVERITY Info
EXPORT NEOCHAT
)
ecm_qt_declare_logging_category(neochat
HEADER "voip_logging.h"
IDENTIFIER "voip"
CATEGORY_NAME "org.kde.neochat.voip"
)
add_executable(neochat-app
main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/res.generated.qrc
res.qrc
)
target_include_directories(neochat-app PRIVATE ${CMAKE_BINARY_DIR})
@@ -149,16 +82,24 @@ target_link_libraries(neochat-app PRIVATE
neochat
)
if(Quotient${QUOTIENT_SUFFIX}_VERSION_MINOR GREATER 6)
target_compile_definitions(neochat PUBLIC QUOTIENT_07)
target_sources(neochat PRIVATE events/pollevent.cpp pollhandler.cpp)
else()
target_compile_definitions(neochat PUBLIC QUOTIENT_VERSION=\"${Quotient${QUOTIENT_SUFFIX}_VERSION}\")
target_sources(neochat PRIVATE neochataccountregistry.cpp)
endif()
ecm_add_app_icon(NEOCHAT_ICON ICONS ${CMAKE_SOURCE_DIR}/128-logo.png)
target_sources(neochat-app PRIVATE ${NEOCHAT_ICON})
if(NOT ANDROID)
target_sources(neochat PRIVATE colorschemer.cpp colorschemer.h)
target_sources(neochat PRIVATE colorschemer.cpp)
if (NOT WIN32 AND NOT APPLE)
target_sources(neochat PRIVATE trayicon_sni.cpp trayicon_sni.h)
target_sources(neochat PRIVATE trayicon_sni.cpp)
else()
target_sources(neochat PRIVATE trayicon.cpp trayicon.h)
target_sources(neochat PRIVATE trayicon.cpp)
endif()
target_link_libraries(neochat PUBLIC KF${QT_MAJOR_VERSION}::ConfigWidgets KF${QT_MAJOR_VERSION}::WindowSystem)
target_compile_definitions(neochat PUBLIC -DHAVE_COLORSCHEME)
@@ -175,7 +116,21 @@ else()
endif()
target_include_directories(neochat PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(neochat PUBLIC Qt::Core Qt::Quick Qt::Qml Qt::Gui Qt::Multimedia Qt::Network Qt::QuickControls2 KF${QT_MAJOR_VERSION}::I18n KF${QT_MAJOR_VERSION}::Kirigami2 KF${QT_MAJOR_VERSION}::Notifications KF${QT_MAJOR_VERSION}::ConfigCore KF${QT_MAJOR_VERSION}::ConfigGui KF${QT_MAJOR_VERSION}::CoreAddons KF${QT_MAJOR_VERSION}::SonnetCore KF${QT_MAJOR_VERSION}::ItemModels Quotient${QUOTIENT_SUFFIX} cmark::cmark QCoro::Core)
target_link_libraries(neochat PUBLIC Qt::Core Qt::Quick Qt::Qml Qt::Gui Qt::Multimedia Qt::Network Qt::QuickControls2 KF${QT_MAJOR_VERSION}::I18n KF${QT_MAJOR_VERSION}::Kirigami2 KF${QT_MAJOR_VERSION}::Notifications KF${QT_MAJOR_VERSION}::ConfigCore KF${QT_MAJOR_VERSION}::ConfigGui KF${QT_MAJOR_VERSION}::CoreAddons KF${QT_MAJOR_VERSION}::SonnetCore KF${QT_MAJOR_VERSION}::ItemModels Quotient${QUOTIENT_SUFFIX} cmark::cmark ${QTKEYCHAIN_LIBRARIES} QCoro::Core)
if (TARGET PkgConfig::GSTREAMER)
target_link_libraries(neochat PUBLIC PkgConfig::GSTREAMER)
target_sources(neochat PRIVATE
call/callmanager.cpp
call/callsession.cpp
call/audiosources.cpp
call/videosources.cpp
call/devicemonitor.cpp
models/callparticipantsmodel.cpp
call/callparticipant.cpp
)
target_compile_definitions(neochat PUBLIC GSTREAMER_AVAILABLE)
endif()
kconfig_add_kcfg_files(neochat GENERATE_MOC neochatconfig.kcfgc)
if(NEOCHAT_FLATPAK)

View File

@@ -3,8 +3,8 @@
#include "actionshandler.h"
#include <Quotient/csapi/joining.h>
#include <Quotient/events/roommemberevent.h>
#include <csapi/joining.h>
#include <events/roommemberevent.h>
#include <cmark.h>
@@ -14,6 +14,7 @@
#include "models/actionsmodel.h"
#include "models/customemojimodel.h"
#include "neochatconfig.h"
#include "neochatroom.h"
#include "texthandler.h"
using namespace Quotient;
@@ -182,5 +183,3 @@ void ActionsHandler::checkEffects(const QString &text)
Q_EMIT showEffect(*effect);
}
}
#include "moc_actionshandler.cpp"

View File

@@ -5,7 +5,7 @@
#include <QObject>
#include <Quotient/events/roommessageevent.h>
#include <events/roommessageevent.h>
#include "neochatroom.h"
@@ -47,7 +47,7 @@ public:
Q_SIGNALS:
void roomChanged();
void showEffect(const QString &effect);
void showEffect(QString effect);
public Q_SLOTS:

99
src/call/audiosources.cpp Normal file
View File

@@ -0,0 +1,99 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "audiosources.h"
#include <gst/gst.h>
#include <QDebug>
#include <QString>
#include "devicemonitor.h"
#include "neochatconfig.h"
int AudioSources::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return DeviceMonitor::instance().audioSources().size();
}
QVariant AudioSources::data(const QModelIndex &index, int role) const
{
if (index.row() >= DeviceMonitor::instance().audioSources().size()) {
return QVariant(QStringLiteral("DEADBEEF"));
}
if (role == TitleRole) {
return DeviceMonitor::instance().audioSources()[index.row()]->title;
}
return QVariant();
}
QHash<int, QByteArray> AudioSources::roleNames() const
{
return {
{TitleRole, "title"},
};
}
AudioSources::AudioSources()
: QAbstractListModel()
{
connect(&DeviceMonitor::instance(), &DeviceMonitor::audioSourceAdded, this, [this]() {
beginResetModel();
endResetModel();
Q_EMIT currentIndexChanged();
});
connect(&DeviceMonitor::instance(), &DeviceMonitor::audioSourceRemoved, this, [this]() {
beginResetModel();
endResetModel();
Q_EMIT currentIndexChanged();
});
}
GstDevice *AudioSources::currentDevice() const
{
const auto config = NeoChatConfig::self();
const QString name = config->microphone();
for (const auto &audioSource : DeviceMonitor::instance().audioSources()) {
if (audioSource->title == name) {
qDebug() << "WebRTC: microphone:" << name;
return audioSource->device;
}
}
return DeviceMonitor::instance().audioSources()[0]->device;
}
void AudioSources::setCurrentIndex(int index) const
{
if (DeviceMonitor::instance().audioSources().size() == 0) {
return;
}
NeoChatConfig::setMicrophone(DeviceMonitor::instance().audioSources()[index]->title);
NeoChatConfig::self()->save();
}
int AudioSources::currentIndex() const
{
const auto config = NeoChatConfig::self();
const QString name = config->microphone();
if (name.isEmpty()) {
return getDefaultDeviceIndex();
}
for (auto i = 0; i < DeviceMonitor::instance().audioSources().size(); i++) {
if (DeviceMonitor::instance().audioSources()[i]->title == name) {
return i;
}
}
return 0;
}
int AudioSources::getDefaultDeviceIndex() const
{
for (auto i = 0; i < DeviceMonitor::instance().audioSources().size(); i++) {
if (DeviceMonitor::instance().audioSources()[i]->isDefault) {
return i;
}
}
return 0;
}

41
src/call/audiosources.h Normal file
View File

@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <QtCore/QAbstractListModel>
#include <gst/gst.h>
class AudioSources : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
public:
enum Roles {
TitleRole = Qt::UserRole + 1,
};
static AudioSources &instance()
{
static AudioSources _instance;
return _instance;
}
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
GstDevice *currentDevice() const;
void setCurrentIndex(int index) const;
int currentIndex() const;
Q_SIGNALS:
void currentIndexChanged();
private:
AudioSources();
int getDefaultDeviceIndex() const;
};

199
src/call/calldevices.cpp Normal file
View File

@@ -0,0 +1,199 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "calldevices.h"
#include "audiodevicesmodel.h"
#include "neochatconfig.h"
#include "videodevicesmodel.h"
#include <QStringView>
#include <cstring>
#include <optional>
#include "voiplogging.h"
#ifdef GSTREAMER_AVAILABLE
extern "C" {
#include "gst/gst.h"
}
#endif
#ifdef GSTREAMER_AVAILABLE
CallDevices::CallDevices()
: QObject()
, m_audioDevicesModel(new AudioDevicesModel(this))
, m_videoDevicesModel(new VideoDevicesModel(this))
{
init();
}
AudioDevicesModel *CallDevices::audioDevicesModel() const
{
return m_audioDevicesModel;
}
VideoDevicesModel *CallDevices::videoDevicesModel() const
{
return m_videoDevicesModel;
}
void CallDevices::addDevice(GstDevice *device)
{
if (!device)
return;
gchar *type = gst_device_get_device_class(device);
bool isVideo = !std::strncmp(type, "Video", 5);
g_free(type);
if (isVideo) {
m_videoDevicesModel->addDevice(device);
m_videoDevicesModel->setDefaultDevice();
} else {
m_audioDevicesModel->addDevice(device);
m_audioDevicesModel->setDefaultDevice();
}
}
void CallDevices::removeDevice(GstDevice *device, bool changed)
{
if (device) {
if (m_audioDevicesModel->removeDevice(device, changed) || m_videoDevicesModel->removeDevice(device, changed))
return;
}
}
namespace
{
gboolean newBusMessage(GstBus *bus, GstMessage *msg, gpointer user_data)
{
Q_UNUSED(bus)
Q_UNUSED(user_data)
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_DEVICE_ADDED: {
GstDevice *device;
gst_message_parse_device_added(msg, &device);
CallDevices::instance().addDevice(device);
Q_EMIT CallDevices::instance().devicesChanged();
break;
}
case GST_MESSAGE_DEVICE_REMOVED: {
GstDevice *device;
gst_message_parse_device_removed(msg, &device);
CallDevices::instance().removeDevice(device, false);
Q_EMIT CallDevices::instance().devicesChanged();
break;
}
case GST_MESSAGE_DEVICE_CHANGED: {
GstDevice *device;
GstDevice *oldDevice;
gst_message_parse_device_changed(msg, &device, &oldDevice);
CallDevices::instance().removeDevice(oldDevice, true);
CallDevices::instance().addDevice(device);
Q_EMIT CallDevices::instance().devicesChanged();
break;
}
default:
break;
}
return true;
}
}
void CallDevices::init()
{
static GstDeviceMonitor *monitor = nullptr;
if (!monitor) {
monitor = gst_device_monitor_new();
Q_ASSERT(monitor);
GstCaps *caps = gst_caps_new_empty_simple("audio/x-raw");
gst_device_monitor_add_filter(monitor, "Audio/Source", caps);
gst_device_monitor_add_filter(monitor, "Audio/Duplex", caps);
gst_caps_unref(caps);
caps = gst_caps_new_empty_simple("video/x-raw");
gst_device_monitor_add_filter(monitor, "Video/Source", caps);
gst_device_monitor_add_filter(monitor, "Video/Duplex", caps);
gst_caps_unref(caps);
GstBus *bus = gst_device_monitor_get_bus(monitor);
gst_bus_add_watch(bus, newBusMessage, nullptr);
gst_object_unref(bus);
if (!gst_device_monitor_start(monitor)) {
qCCritical(voip) << "Failed to start device monitor";
return;
} else {
qCDebug(voip) << "Device monitor started";
}
}
}
bool CallDevices::hasMicrophone() const
{
return m_audioDevicesModel->hasMicrophone();
}
bool CallDevices::hasCamera() const
{
return m_videoDevicesModel->hasCamera();
}
QStringList CallDevices::resolutions(const QString &cameraName) const
{
return m_videoDevicesModel->resolutions(cameraName);
}
QStringList CallDevices::frameRates(const QString &cameraName, const QString &resolution) const
{
if (auto s = m_videoDevicesModel->getVideoSource(cameraName); s) {
if (auto it = std::find_if(s->caps.cbegin(),
s->caps.cend(),
[&](const auto &c) {
return c.resolution == resolution;
});
it != s->caps.cend())
return it->frameRates;
}
return {};
}
GstDevice *CallDevices::audioDevice() const
{
return m_audioDevicesModel->currentDevice();
}
GstDevice *CallDevices::videoDevice(QPair<int, int> &resolution, QPair<int, int> &frameRate) const
{
return m_videoDevicesModel->currentDevice(resolution, frameRate);
}
#else
bool CallDevices::hasMicrophone() const
{
return false;
}
bool CallDevices::hasCamera() const
{
return false;
}
QStringList CallDevices::names(bool, const QString &) const
{
return {};
}
QStringList CallDevices::resolutions(const QString &) const
{
return {};
}
QStringList CallDevices::frameRates(const QString &, const QString &) const
{
return {};
}
#endif

64
src/call/calldevices.h Normal file
View File

@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: 2021 Contributors
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <string>
#include <utility>
#include <vector>
#include <QObject>
typedef struct _GstDevice GstDevice;
class CallDevices;
class AudioDevicesModel;
class VideoDevicesModel;
class CallDevices : public QObject
{
Q_OBJECT
Q_PROPERTY(AudioDevicesModel *audioDevices READ audioDevicesModel CONSTANT);
Q_PROPERTY(VideoDevicesModel *videoDevices READ videoDevicesModel CONSTANT);
public:
static CallDevices &instance()
{
static CallDevices instance;
return instance;
}
CallDevices(CallDevices const &) = delete;
void operator=(CallDevices const &) = delete;
bool hasMicrophone() const;
bool hasCamera() const;
QStringList names(bool isVideo, const QString &defaultDevice) const;
QStringList resolutions(const QString &cameraName) const;
QStringList frameRates(const QString &cameraName, const QString &resolution) const;
AudioDevicesModel *audioDevicesModel() const;
VideoDevicesModel *videoDevicesModel() const;
void addDevice(GstDevice *device);
void removeDevice(GstDevice *device, bool changed);
Q_SIGNALS:
void devicesChanged();
private:
CallDevices();
void init();
GstDevice *audioDevice() const;
GstDevice *videoDevice(QPair<int, int> &resolution, QPair<int, int> &frameRate) const;
AudioDevicesModel *m_audioDevicesModel;
VideoDevicesModel *m_videoDevicesModel;
friend class CallSession;
friend class Audio;
};

617
src/call/callmanager.cpp Normal file
View File

@@ -0,0 +1,617 @@
// SPDX-FileCopyrightText: 2020-2021 Nheko Authors
// SPDX-FileCopyrightText: 2021-2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "callmanager.h"
#include "controller.h"
#include <gst/gst.h>
#include "voiplogging.h"
#include <KLocalizedString>
#include <QDateTime>
#include <QMediaPlaylist>
#include <QMimeDatabase>
#include <qcoro/qcorosignal.h>
#include <qt_connection_util.h>
#include "neochatconfig.h"
#define CALL_VERSION "1"
CallManager::CallManager()
{
init();
connect(&Controller::instance(), &Controller::activeConnectionChanged, this, [this] {
updateTurnServers();
});
}
QCoro::Task<void> CallManager::updateTurnServers()
{
if (m_cachedTurnUrisValidUntil > QDateTime::currentDateTime()) {
co_return;
}
Controller::instance().activeConnection()->getTurnServers();
auto servers = co_await qCoro(Controller::instance().activeConnection(), &Connection::turnServersChanged);
m_cachedTurnUrisValidUntil = QDateTime::currentDateTime().addSecs(servers["ttl"].toInt());
const auto password = servers["password"].toString();
const auto username = servers["username"].toString();
const auto uris = servers["uris"].toArray();
m_cachedTurnUris.clear();
for (const auto &u : uris) {
QString uri = u.toString();
auto c = uri.indexOf(':');
if (c == -1) {
qCWarning(voip) << "Invalid TURN URI:" << uri;
continue;
}
QString scheme = uri.left(c);
if (scheme != "turn" && scheme != "turns") {
qCWarning(voip) << "Invalid TURN scheme:" << scheme;
continue;
}
m_cachedTurnUris += QStringLiteral("%1://%2:%3@%4").arg(scheme, QUrl::toPercentEncoding(username), QUrl::toPercentEncoding(password), uri.mid(c + 1));
}
}
QString CallManager::callId() const
{
return m_callId;
}
void CallManager::handleCallEvent(NeoChatRoom *room, const Quotient::RoomEvent *event)
{
if (const auto &inviteEvent = eventCast<const CallInviteEvent>(event)) {
handleInvite(room, inviteEvent);
} else if (const auto &hangupEvent = eventCast<const CallHangupEvent>(event)) {
handleHangup(room, hangupEvent);
} else if (const auto &candidatesEvent = eventCast<const CallCandidatesEvent>(event)) {
handleCandidates(room, candidatesEvent);
} else if (const auto &answerEvent = eventCast<const CallAnswerEvent>(event)) {
handleAnswer(room, answerEvent);
} else if (const auto &negotiateEvent = eventCast<const CallNegotiateEvent>(event)) {
handleNegotiate(room, negotiateEvent);
}
}
void CallManager::checkStartCall()
{
if ((m_incomingCandidates.isEmpty() && !m_incomingSdp.contains("candidates"_ls)) || m_incomingSdp.isEmpty()) {
qCDebug(voip) << "Not ready to start this call yet";
return;
}
m_session->acceptAnswer(m_incomingSdp, m_incomingCandidates, m_remoteUser->id());
m_incomingCandidates.clear();
m_incomingSdp.clear();
setGlobalState(ACTIVE);
}
void CallManager::handleAnswer(NeoChatRoom *room, const Quotient::CallAnswerEvent *event)
{
if (globalState() != OUTGOING) {
qCDebug(voip) << "Ignoring answer while in state" << globalState();
return;
}
if (event->callId() != m_callId) {
qCDebug(voip) << "Ignoring answer for unknown call id" << event->callId() << ". Our call id is" << m_callId;
return;
}
if (event->senderId() == room->localUser()->id() && partyId() == event->contentJson()["party_id"].toString()) {
qCDebug(voip) << "Ignoring echo for answer";
return;
}
if (event->senderId() == room->localUser()->id()) {
qCDebug(voip) << "Call was accepted on a different device";
// Show the user that call was accepted on a different device
// Stop ringing
return;
}
// TODO handle that MSC wrt to accepting on other devices
m_session->setMetadata(event->contentJson()["org.matrix.msc3077.sdp_stream_metadata"].toObject());
m_remotePartyId = event->contentJson()["party_id"].toString();
m_incomingSdp = event->sdp();
checkStartCall();
}
void CallManager::handleCandidates(NeoChatRoom *room, const Quotient::CallCandidatesEvent *event)
{
// TODO what if candidates come before invite? this looks wrong
if (globalState() == IDLE) {
qCDebug(voip) << "Ignoring candidates in state" << globalState();
return;
}
if (event->senderId() == room->localUser()->id()) {
qCDebug(voip) << "Ignoring candidates sent by ourself";
return;
}
if (globalState() == ACTIVE) {
QVector<Candidate> candidates;
for (const auto &candidate : event->candidates()) {
candidates += Candidate{candidate.toObject()["candidate"].toString(),
candidate.toObject()["sdpMLineIndex"].toInt(),
candidate.toObject()["sdpMid"].toString()};
}
m_session->acceptCandidates(candidates);
return;
}
qCDebug(voip) << "Storing" << event->candidates().size() << "incoming candidates";
for (const auto &candidate : event->candidates()) {
m_incomingCandidates +=
Candidate{candidate.toObject()["candidate"].toString(), candidate.toObject()["sdpMLineIndex"].toInt(), candidate.toObject()["sdpMid"].toString()};
}
if (globalState() == OUTGOING) {
checkStartCall();
}
}
void CallManager::handleInvite(NeoChatRoom *room, const Quotient::CallInviteEvent *event)
{
if (event->senderId() == room->localUser()->id()) {
qCDebug(voip) << "Igoring invite sent by ourself";
return;
}
if (globalState() != IDLE) {
// TODO handle glare
qCDebug(voip) << "Ignoring invite while already in a call";
return;
}
if (event->originTimestamp() < QDateTime::currentDateTime().addSecs(-60)) {
qCDebug(voip) << "Ignoring outdated invite; sent at:" << event->originTimestamp() << "current:" << QDateTime::currentDateTime();
return;
}
setGlobalState(INCOMING);
m_incomingSdp = event->sdp();
setRemoteUser(dynamic_cast<NeoChatUser *>(room->user(event->senderId())));
setRoom(room);
setCallId(event->callId());
setPartyId(generatePartyId());
m_remotePartyId = event->contentJson()["party_id"].toString();
setLifetime(event->lifetime());
Q_EMIT incomingCall(remoteUser(), room, event->lifetime(), callId());
ring(event->lifetime());
}
void CallManager::handleNegotiate(NeoChatRoom *room, const Quotient::CallNegotiateEvent *event)
{
Q_UNUSED(room);
if (event->callId() != m_callId) {
qCDebug(voip) << "Ignoring negotiate for unknown call id" << event->callId() << ". Our call id is" << m_callId;
return;
}
if (event->partyId() != m_remotePartyId) {
qCDebug(voip) << "Ignoring negotiate for unknown party id" << event->partyId() << ". Remote party id is" << m_remotePartyId;
return;
}
if (event->senderId() != m_remoteUser->id()) {
qCDebug(voip) << "Ignoring negotiate for unknown user id" << event->senderId() << ". Remote user id is" << m_remoteUser->id();
return;
}
// TODO DUPLICATES FFS
m_session->setMetadata(event->contentJson()["org.matrix.msc3077.sdp_stream_metadata"].toObject());
m_session->renegotiateOffer(event->sdp(), m_remoteUser->id(), event->contentJson()["description"]["type"] == QStringLiteral("answer"));
}
void CallManager::ring(int lifetime)
{
// TODO put a better default ringtone in the kcfg
// TODO which one? ship one? plasma-mobile-sounds?
if (!QFileInfo::exists(NeoChatConfig::ringtone())) {
qCWarning(voip) << "Ringtone file doesn't exist. Not audibly ringing";
return;
}
auto ringtone = QUrl::fromLocalFile(NeoChatConfig::ringtone());
m_playlist.setPlaybackMode(QMediaPlaylist::Loop);
m_playlist.clear();
m_ringPlayer.setPlaylist(&m_playlist);
m_playlist.addMedia(ringtone);
m_ringPlayer.play();
QTimer::singleShot(lifetime, this, [this]() {
stopRinging();
Q_EMIT callEnded();
});
}
void CallManager::stopRinging()
{
m_ringPlayer.stop();
}
void CallManager::handleHangup(NeoChatRoom *room, const Quotient::CallHangupEvent *event)
{
if (globalState() == IDLE) {
qCDebug(voip) << "Ignoring hangup since we're not in a call";
return;
}
if (event->senderId() == room->localUser()->id()) {
qCDebug(voip) << "Ignoring hangup we sent ourselves";
// TODO hangup-to-decline by different device?
return;
}
if (event->callId() != m_callId) {
qCDebug(voip) << "Hangup not for this call. Event's call id:" << event->callId() << ". Our call id" << m_callId;
return;
}
stopRinging();
if (m_session) {
m_session->end();
delete m_session;
}
setGlobalState(IDLE);
Q_EMIT callEnded();
}
void CallManager::acceptCall()
{
// TODO metadata for this case
if (globalState() != INCOMING) {
qCWarning(voip) << "Not accepting call while state is" << globalState();
return;
}
stopRinging();
if (!checkPlugins()) {
qCCritical(voip) << "Missing plugins; can't accept call";
}
updateTurnServers();
// TODO wait until candidates are here
m_session = CallSession::acceptCall(m_incomingSdp, m_incomingCandidates, m_cachedTurnUris, m_remoteUser->id(), this);
m_participants->clear();
connect(m_session.data(), &CallSession::stateChanged, this, [this] {
Q_EMIT stateChanged();
if (state() == CallSession::ICEFAILED) {
Q_EMIT callEnded();
}
}); // TODO refactor away?
m_incomingCandidates.clear();
connectSingleShot(m_session.data(), &CallSession::answerCreated, this, [this](const QString &_sdp, const QVector<Candidate> &candidates) {
const auto &[uuids, sdp] = mangleSdp(_sdp);
QVector<std::pair<QString, QString>> msidToPurpose;
for (const auto &uuid : uuids) {
msidToPurpose += {uuid, "m.usermedia"}; // TODO
}
auto answer = createAnswer(m_callId, sdp, msidToPurpose);
m_room->postJson("m.call.answer", answer);
qCWarning(voip) << "Sending Answer";
auto c = createCandidates(m_callId, candidates);
auto cand = createCandidates(m_callId, candidates);
m_room->postJson("m.call.candidates", cand);
qCWarning(voip) << "Sending Candidates";
setGlobalState(ACTIVE);
});
}
void CallManager::hangupCall()
{
qCDebug(voip) << "Ending call";
if (m_session) {
m_session->end();
delete m_session;
m_session = nullptr;
}
stopRinging();
m_room->postJson("m.call.hangup", createHangup(m_callId));
setGlobalState(IDLE);
Q_EMIT callEnded();
}
NeoChatUser *CallManager::remoteUser() const
{
return m_remoteUser;
}
NeoChatRoom *CallManager::room() const
{
return m_room;
}
CallSession::State CallManager::state() const
{
if (!m_session) {
return CallSession::DISCONNECTED;
}
return m_session->state();
}
int CallManager::lifetime() const
{
return m_lifetime;
}
void CallManager::ignoreCall()
{
setLifetime(0);
setCallId({});
setRoom(nullptr);
setRemoteUser(nullptr);
}
void CallManager::startCall(NeoChatRoom *room)
{
if (m_session) {
// Don't start calls if there already is one
Q_EMIT Controller::instance().errorOccured(i18n("A call is already started"));
return;
}
if (room->users().size() != 2) {
// Don't start calls if the room doesn't have exactly two members
Q_EMIT Controller::instance().errorOccured(i18n("Calls are limited to 1:1 rooms"));
return;
}
auto missingPlugins = CallSession::missingPlugins();
if (!missingPlugins.isEmpty()) {
qCCritical(voip) << "Missing GStreamer plugins:" << missingPlugins;
Q_EMIT Controller::instance().errorOccured("Missing GStreamer plugins.");
return;
}
setLifetime(60000);
setRoom(room);
setRemoteUser(otherUser(room));
updateTurnServers();
setCallId(generateCallId());
setPartyId(generatePartyId());
m_participants->clear();
for (const auto &user : m_room->users()) {
auto participant = new CallParticipant(m_session);
participant->m_user = dynamic_cast<NeoChatUser *>(user);
m_participants->addParticipant(participant);
}
m_session = CallSession::startCall(m_cachedTurnUris, this);
setGlobalState(OUTGOING);
connect(m_session, &CallSession::stateChanged, this, [this] {
Q_EMIT stateChanged();
if (state() == CallSession::ICEFAILED) {
Q_EMIT callEnded();
}
});
connectSingleShot(m_session.data(), &CallSession::offerCreated, this, [this](const QString &_sdp, const QVector<Candidate> &candidates) {
const auto &[uuids, sdp] = mangleSdp(_sdp);
QVector<std::pair<QString, QString>> msidToPurpose;
for (const auto &uuid : uuids) {
msidToPurpose += {uuid, "m.usermedia"}; // TODO
}
qCWarning(voip) << "Sending Invite";
qCWarning(voip) << "Sending Candidates";
auto invite = createInvite(m_callId, sdp, msidToPurpose);
auto c = createCandidates(m_callId, candidates);
m_room->postJson("m.call.invite", invite);
m_room->postJson("m.call.candidates", c);
});
connect(m_session, &CallSession::renegotiate, this, [this](const QString &sdp, const QString &type) {
QVector<std::pair<QString, QString>> msidToPurpose;
const auto &[uuids, _sdp] = mangleSdp(sdp);
for (const auto &uuid : uuids) {
msidToPurpose += {uuid, "m.usermedia"}; // TODO
}
QJsonObject json{
{QStringLiteral("lifetime"), 60000},
{QStringLiteral("version"), 1},
{QStringLiteral("description"), QJsonObject{{QStringLiteral("type"), type}, {QStringLiteral("sdp"), _sdp}}}, // AAAAA
{QStringLiteral("party_id"), m_partyId},
{QStringLiteral("call_id"), m_callId},
};
QJsonObject metadata;
for (const auto &[stream, purpose] : msidToPurpose) {
QJsonObject data = {{"purpose", purpose}};
metadata[stream] = data;
}
json["org.matrix.msc3077.sdp_stream_metadata"] = metadata;
m_room->postJson("m.call.negotiate", json);
});
}
QString CallManager::generateCallId() const
{
return QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz");
}
QString CallManager::generatePartyId() const
{
return QUuid::createUuid().toString();
}
void CallManager::setCallId(const QString &callId)
{
m_callId = callId;
Q_EMIT callIdChanged();
}
void CallManager::setPartyId(const QString &partyId)
{
m_partyId = partyId;
}
void CallManager::setMuted(bool muted)
{
if (!m_session) {
return;
}
m_session->setMuted(muted);
Q_EMIT mutedChanged();
}
bool CallManager::muted() const
{
if (!m_session) {
return false;
}
return m_session->muted();
}
bool CallManager::init()
{
qRegisterMetaType<Candidate>();
qRegisterMetaType<QVector<Candidate>>();
GError *error = nullptr;
if (!gst_init_check(nullptr, nullptr, &error)) {
QString strError;
if (error) {
strError += error->message;
g_error_free(error);
}
qCCritical(voip) << "Failed to initialize GStreamer:" << strError;
return false;
}
gchar *version = gst_version_string();
qCDebug(voip) << "GStreamer version" << version;
g_free(version);
// Required to register the qml types
auto _sink = gst_element_factory_make("qmlglsink", nullptr);
Q_ASSERT(_sink);
gst_object_unref(_sink);
return true;
}
void CallManager::setLifetime(int lifetime)
{
m_lifetime = lifetime;
Q_EMIT lifetimeChanged();
}
void CallManager::setRoom(NeoChatRoom *room)
{
m_room = room;
Q_EMIT roomChanged();
}
void CallManager::setRemoteUser(NeoChatUser *user)
{
m_remoteUser = user;
Q_EMIT roomChanged();
}
NeoChatUser *CallManager::otherUser(NeoChatRoom *room)
{
return dynamic_cast<NeoChatUser *>(room->users()[0]->id() == room->localUser()->id() ? room->users()[1] : room->users()[0]);
}
QJsonObject CallManager::createCandidates(const QString &callId, const QVector<Candidate> &candidates) const
{
QJsonArray candidatesJson;
for (const auto &candidate : candidates) {
candidatesJson += QJsonObject{{"candidate", candidate.candidate}, {"sdpMid", candidate.sdpMid}, {"sdpMLineIndex", candidate.sdpMLineIndex}};
}
return QJsonObject{{"call_id", callId}, {"candidates", candidatesJson}, {"version", CALL_VERSION}, {"party_id", "todopartyid"}};
}
void CallManager::setGlobalState(GlobalState globalState)
{
if (m_globalState == globalState) {
return;
}
m_globalState = globalState;
Q_EMIT globalStateChanged();
}
CallManager::GlobalState CallManager::globalState() const
{
return m_globalState;
}
CallParticipantsModel *CallManager::callParticipants() const
{
return m_participants;
}
std::pair<QStringList, QString> CallManager::mangleSdp(const QString &_sdp)
{
QString sdp = _sdp;
QRegularExpression regex("msid:user[0-9]+@host-[0-9a-f]+ webrtctransceiver([0-9])");
auto iter = regex.globalMatch(sdp);
QStringList uuids;
while (iter.hasNext()) {
auto uuid = QUuid::createUuid();
auto match = iter.next();
uuids += uuid.toString();
sdp.replace(match.captured(), QStringLiteral("msid:") + uuid.toString() + QStringLiteral(" foo"));
}
return {uuids, sdp};
}
QJsonObject CallManager::createInvite(const QString &callId, const QString &sdp, const QVector<std::pair<QString, QString>> &msidToPurpose) const
{
QJsonObject metadata;
for (const auto &[msid, purpose] : msidToPurpose) {
metadata[msid] = QJsonObject{{"purpose", purpose}};
}
return {{"call_id", callId},
{"party_id", "todopartyid"},
{"lifetime", 60000},
{"capabilities", QJsonObject{{"m.call.transferee", false}}},
{"offer", QJsonObject{{"sdp", sdp}, {"type", "offer"}}},
{"org.matrix.msc3077.sdp_stream_metadata", metadata},
{"version", CALL_VERSION}};
}
QJsonObject CallManager::createHangup(const QString &callId) const
{
return {{"call_id", callId}, {"party_id", "todopartyid"}, {"version", CALL_VERSION}};
}
QJsonObject CallManager::createAnswer(const QString &callId, const QString &sdp, const QVector<std::pair<QString, QString>> &msidToPurpose) const
{
Q_ASSERT(!callId.isEmpty());
QJsonObject metadata;
for (const auto &[msid, purpose] : msidToPurpose) {
metadata[msid] = QJsonObject{{"purpose", purpose}};
}
return {{"call_id", callId},
{"party_id", "todopartyid"},
{"lifetime", "lifetime"},
{"capabilities", QJsonObject{{"m.call.transferee", false}}},
{"offer", QJsonObject{{"sdp", sdp}, {"type", "offer"}}},
{"org.matrix.msc3077.sdp_stream_metadata", metadata},
{"version", CALL_VERSION}};
}
void CallManager::toggleCamera()
{
m_session->toggleCamera();
}
QString CallManager::partyId() const
{
return m_partyId;
}
bool CallManager::checkPlugins() const
{
auto missingPlugins = m_session->missingPlugins();
if (!missingPlugins.isEmpty()) {
qCCritical(voip) << "Missing GStreamer plugins:" << missingPlugins;
Q_EMIT Controller::instance().errorOccured("Missing GStreamer plugins.");
}
return !missingPlugins.isEmpty();
}

159
src/call/callmanager.h Normal file
View File

@@ -0,0 +1,159 @@
// SPDX-FileCopyrightText: 2020-2021 Nheko Authors
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include "neochatroom.h"
#include "neochatuser.h"
#include <QAbstractListModel>
#include <QObject>
#include <QString>
#include <events/roomevent.h>
#include "callsession.h"
#include "models/callparticipantsmodel.h"
#include <events/callevents.h>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QTimer>
#include <qcoro/task.h>
#include <qobjectdefs.h>
class CallSession;
class QQuickItem;
using namespace Quotient;
class CallManager : public QObject
{
Q_OBJECT
public:
enum GlobalState {
IDLE,
INCOMING,
OUTGOING,
ACTIVE,
};
Q_ENUM(GlobalState);
Q_PROPERTY(GlobalState globalState READ globalState NOTIFY globalStateChanged)
Q_PROPERTY(NeoChatUser *remoteUser READ remoteUser NOTIFY remoteUserChanged)
Q_PROPERTY(QString callId READ callId NOTIFY callIdChanged)
Q_PROPERTY(NeoChatRoom *room READ room NOTIFY roomChanged)
Q_PROPERTY(int lifetime READ lifetime NOTIFY lifetimeChanged)
Q_PROPERTY(bool muted READ muted WRITE setMuted NOTIFY mutedChanged)
Q_PROPERTY(QQuickItem *item MEMBER m_item) // TODO allow for different devices for each session
Q_PROPERTY(CallSession::State state READ state NOTIFY stateChanged)
Q_PROPERTY(CallParticipantsModel *callParticipants READ callParticipants CONSTANT)
static CallManager &instance()
{
static CallManager _instance;
return _instance;
}
[[nodiscard]] QString callId() const;
[[nodiscard]] QString partyId() const;
CallSession::State state() const;
NeoChatUser *remoteUser() const;
NeoChatRoom *room() const;
int lifetime() const;
bool muted() const;
void setMuted(bool muted);
CallManager::GlobalState globalState() const;
void handleCallEvent(NeoChatRoom *room, const RoomEvent *event);
Q_INVOKABLE void startCall(NeoChatRoom *room);
Q_INVOKABLE void acceptCall();
Q_INVOKABLE void hangupCall();
Q_INVOKABLE void ignoreCall();
Q_INVOKABLE void toggleCamera();
QCoro::Task<void> updateTurnServers();
[[nodiscard]] CallParticipantsModel *callParticipants() const;
QQuickItem *m_item = nullptr;
Q_SIGNALS:
void currentCallIdChanged();
void incomingCall(NeoChatUser *user, NeoChatRoom *room, int timeout, const QString &callId);
void callEnded();
void remoteUserChanged();
void callIdChanged();
void roomChanged();
void stateChanged();
void lifetimeChanged();
void mutedChanged();
void globalStateChanged();
private:
CallManager();
QString m_callId;
QVector<Candidate> m_incomingCandidates;
QString m_incomingSdp;
[[nodiscard]] bool checkPlugins() const;
QStringList m_cachedTurnUris;
QDateTime m_cachedTurnUrisValidUntil = QDateTime::fromSecsSinceEpoch(0);
NeoChatUser *m_remoteUser = nullptr;
NeoChatRoom *m_room = nullptr;
QString m_remotePartyId;
QString m_partyId;
int m_lifetime = 0;
GlobalState m_globalState = IDLE;
void handleInvite(NeoChatRoom *room, const CallInviteEvent *event);
void handleHangup(NeoChatRoom *room, const CallHangupEvent *event);
void handleCandidates(NeoChatRoom *room, const CallCandidatesEvent *event);
void handleAnswer(NeoChatRoom *room, const CallAnswerEvent *event);
void handleNegotiate(NeoChatRoom *room, const CallNegotiateEvent *event);
void checkStartCall();
void ring(int lifetime);
void stopRinging();
[[nodiscard]] QString generateCallId() const;
[[nodiscard]] QString generatePartyId() const;
bool init();
bool m_initialised = false;
QPointer<CallSession> m_session = nullptr;
void setLifetime(int lifetime);
void setRoom(NeoChatRoom *room);
void setRemoteUser(NeoChatUser *user);
void setCallId(const QString &callId);
void setPartyId(const QString &partyId);
void setGlobalState(GlobalState state);
std::pair<QStringList, QString> mangleSdp(const QString &sdp);
CallParticipantsModel *m_participants = new CallParticipantsModel();
NeoChatUser *otherUser(NeoChatRoom *room);
[[nodiscard]] QJsonObject createCandidates(const QString &callId, const QVector<Candidate> &candidates) const;
[[nodiscard]] QJsonObject createInvite(const QString &callId, const QString &sdp, const QVector<std::pair<QString, QString>> &msidToPurpose) const;
[[nodiscard]] QJsonObject createHangup(const QString &callId) const;
[[nodiscard]] QJsonObject createAnswer(const QString &callId, const QString &sdp, const QVector<std::pair<QString, QString>> &msidToPurpose) const;
QMediaPlayer m_ringPlayer;
QMediaPlaylist m_playlist;
};

View File

@@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: 2022 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "callnegotiateevent.h"
using namespace Quotient;
CallNegotiateEvent::CallNegotiateEvent(const QString &callId,
const QString &partyId,
int lifetime,
const QString &sdp,
bool answer,
QVector<std::pair<QString, QString>> msidToPurpose)
: EventTemplate(callId,
{
{QStringLiteral("lifetime"), lifetime},
{QStringLiteral("version"), 1},
{QStringLiteral("description"),
QJsonObject{{QStringLiteral("type"), answer ? QStringLiteral("answer") : QStringLiteral("offer")}, {QStringLiteral("sdp"), sdp}}},
{QStringLiteral("party_id"), partyId},
})
{
QJsonObject metadata;
for (const auto &[stream, purpose] : msidToPurpose) {
QJsonObject data = {{"purpose", purpose}};
metadata[stream] = purpose;
}
auto content = editJson();
content["org.matrix.msc3077.sdp_stream_metadata"] = metadata;
editJson()["content"] = content;
}
CallNegotiateEvent::CallNegotiateEvent(const QJsonObject &json)
: EventTemplate(json)
{
}
QString CallNegotiateEvent::partyId() const
{
return contentJson()["party_id"].toString();
}
QString CallNegotiateEvent::sdp() const
{
return contentJson()["description"]["sdp"].toString();
}
QJsonObject CallNegotiateEvent::sdpStreamMetadata() const
{
return contentJson()["org.matrix.msc3077.sdp_stream_metadata"].toObject();
}

View File

@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2022 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <events/callevents.h>
namespace Quotient
{
class CallNegotiateEvent : public EventTemplate<CallNegotiateEvent, CallEvent>
{
public:
QUO_EVENT(CallNegotiateEvent, "m.call.negotiate")
explicit CallNegotiateEvent(const QJsonObject &obj);
explicit CallNegotiateEvent(const QString &callId,
const QString &partyId,
int lifetime,
const QString &sdp,
bool answer,
QVector<std::pair<QString, QString>> msidToPurpose);
QString partyId() const;
QString sdp() const;
// TODO make this a struct instead
QJsonObject sdpStreamMetadata() const;
};
}

View File

@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "callparticipant.h"
NeoChatUser *CallParticipant::user() const
{
return m_user;
}
bool CallParticipant::hasCamera() const
{
return m_hasCamera;
}
CallParticipant::CallParticipant(QObject *parent)
: QObject(parent)
{
}
void CallParticipant::initCamera(QQuickItem *item)
{
QTimer::singleShot(500, this, [=] {
Q_EMIT initialized(item);
});
}

View File

@@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QObject>
#include <QTimer>
#include "neochatuser.h"
class QQuickItem;
class CallParticipant : public QObject
{
Q_OBJECT
Q_PROPERTY(NeoChatUser *user READ user CONSTANT)
Q_PROPERTY(bool hasCamera READ hasCamera NOTIFY hasCameraChanged)
public:
NeoChatUser *m_user = nullptr;
bool m_hasCamera = false;
Q_INVOKABLE void initCamera(QQuickItem *item);
[[nodiscard]] NeoChatUser *user() const;
[[nodiscard]] bool hasCamera() const;
explicit CallParticipant(QObject *parent = nullptr);
Q_SIGNALS:
void initialized(QQuickItem *item);
void heightChanged();
void widthChanged();
void hasCameraChanged();
};

916
src/call/callsession.cpp Normal file
View File

@@ -0,0 +1,916 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
// SPDX-FileCopyrightText: 2021-2022 Tobias Fella <fella@posteo.de>
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "calldevices.h"
#include <QDebug>
#include <QThread>
#include <gst/gst.h>
#define GST_USE_UNSTABLE_API
#include <gst/webrtc/webrtc.h>
#undef GST_USE_UNSTABLE_API
#include "voiplogging.h"
#include "audiosources.h"
#include "videosources.h"
#include <qcoro/qcorosignal.h>
#define private public
#include "callsession.h"
#undef private
#include "callmanager.h"
#include <qt_connection_util.h>
#define STUN_SERVER "stun://turn.matrix.org:3478" // TODO make STUN server configurable
#define INSTANCE \
Q_ASSERT(user_data); \
auto instance = static_cast<CallSession *>(user_data);
GstElement *createElement(const char *type, GstElement *pipe, const char *name = nullptr)
{
auto element = gst_element_factory_make(type, name);
Q_ASSERT_X(element, __FUNCTION__, QStringLiteral("Failed to create element %1 %2").arg(type, name).toLatin1());
if (pipe) {
gst_bin_add_many(GST_BIN(pipe), element, nullptr);
}
return element;
}
GstElement *binGetByName(GstElement *bin, const char *name)
{
auto element = gst_bin_get_by_name(GST_BIN(bin), name);
Q_ASSERT_X(element, __FUNCTION__, QStringLiteral("Failed to get element by name: %1").arg(name).toLatin1());
return element;
}
struct KeyFrameRequestData {
GstElement *pipe = nullptr;
GstElement *decodeBin = nullptr;
gint packetsLost = 0;
guint timerId = 0;
QString statsField;
} keyFrameRequestData;
std::pair<int, int> getResolution(GstPad *pad)
{
std::pair<int, int> ret;
auto caps = gst_pad_get_current_caps(pad);
auto structure = gst_caps_get_structure(caps, 0);
gst_structure_get_int(structure, "width", &ret.first);
gst_structure_get_int(structure, "height", &ret.second);
gst_caps_unref(caps);
return ret;
}
std::pair<int, int> getResolution(GstElement *pipe, const gchar *elementName, const gchar *padName)
{
auto element = binGetByName(pipe, elementName);
auto pad = gst_element_get_static_pad(element, padName);
auto ret = getResolution(pad);
gst_object_unref(pad);
gst_object_unref(element);
return ret;
}
void setLocalDescription(GstPromise *promise, gpointer user_data)
{
INSTANCE
qCDebug(voip) << "Setting local description";
const GstStructure *reply = gst_promise_get_reply(promise);
gboolean isAnswer = gst_structure_id_has_field(reply, g_quark_from_string("answer"));
GstWebRTCSessionDescription *gstsdp = nullptr;
gst_structure_get(reply, isAnswer ? "answer" : "offer", GST_TYPE_WEBRTC_SESSION_DESCRIPTION, &gstsdp, nullptr);
gst_promise_unref(promise);
auto webrtcbin = binGetByName(instance->m_pipe, "webrtcbin");
Q_ASSERT(gstsdp);
g_signal_emit_by_name(webrtcbin, "set-local-description", gstsdp, nullptr);
gchar *sdp = gst_sdp_message_as_text(gstsdp->sdp);
if (!instance->m_localSdp.isEmpty()) {
// This is a renegotiation
qWarning() << "emitting renegotiate";
Q_EMIT instance->renegotiate(QString(sdp), isAnswer ? QStringLiteral("answer") : QStringLiteral("offer"));
}
instance->m_localSdp = QString(sdp);
g_free(sdp);
gst_webrtc_session_description_free(gstsdp);
qCDebug(voip) << "Local description set:" << isAnswer;
}
bool contains(std::string_view str1, std::string_view str2)
{
return std::search(str1.cbegin(),
str1.cend(),
str2.cbegin(),
str2.cend(),
[](unsigned char c1, unsigned char c2) {
return std::tolower(c1) == std::tolower(c2);
})
!= str1.cend();
}
void createOffer(GstElement *webrtc, CallSession *session)
{
// TODO ?!?
if (!session->m_localSdp.isEmpty()) {
return;
}
qCWarning(voip) << "Creating Offer";
auto promise = gst_promise_new_with_change_func(setLocalDescription, session, nullptr);
g_signal_emit_by_name(webrtc, "create-offer", nullptr, promise);
}
void createAnswer(GstPromise *promise, gpointer user_data)
{
INSTANCE
qCDebug(voip) << "Creating Answer";
gst_promise_unref(promise);
promise = gst_promise_new_with_change_func(setLocalDescription, instance, nullptr);
auto webrtcbin = binGetByName(instance->m_pipe, "webrtcbin");
g_signal_emit_by_name(webrtcbin, "create-answer", nullptr, promise);
}
bool getMediaAttributes(const GstSDPMessage *sdp, const char *mediaType, const char *encoding, int &payloadType, bool &receiveOnly, bool &sendOnly)
{
payloadType = -1;
receiveOnly = false;
sendOnly = false;
for (guint mlineIndex = 0; mlineIndex < gst_sdp_message_medias_len(sdp); mlineIndex++) {
const GstSDPMedia *media = gst_sdp_message_get_media(sdp, mlineIndex);
if (!strcmp(gst_sdp_media_get_media(media), mediaType)) {
receiveOnly = gst_sdp_media_get_attribute_val(media, "recvonly") != nullptr;
sendOnly = gst_sdp_media_get_attribute_val(media, "sendonly") != nullptr;
const gchar *rtpval = nullptr;
for (guint n = 0; n == 0 || rtpval; n++) {
rtpval = gst_sdp_media_get_attribute_val_n(media, "rtpmap", n);
if (rtpval && contains(rtpval, encoding)) {
payloadType = QString::fromLatin1(rtpval).toInt();
break;
}
}
return true;
}
}
return false;
}
GstWebRTCSessionDescription *parseSDP(const QString &sdp, GstWebRTCSDPType type)
{
GstSDPMessage *message;
gst_sdp_message_new(&message);
if (gst_sdp_message_parse_buffer((guint8 *)sdp.toLatin1().data(), sdp.size(), message) == GST_SDP_OK) {
return gst_webrtc_session_description_new(type, message);
} else {
qCCritical(voip) << "Failed to parse remote SDP";
gst_sdp_message_free(message);
return nullptr;
}
}
void addLocalICECandidate(GstElement *webrtc, guint mlineIndex, const gchar *candidate, gpointer user_data)
{
Q_UNUSED(webrtc);
INSTANCE
// qCWarning(voip) << "Adding local ICE Candidates";
instance->m_localCandidates += Candidate{candidate, static_cast<int>(mlineIndex), QString()};
}
void iceConnectionStateChanged(GstElement *webrtc, GParamSpec *pspec, gpointer user_data)
{
Q_UNUSED(pspec);
INSTANCE
GstWebRTCICEConnectionState newState;
g_object_get(webrtc, "ice-connection-state", &newState, nullptr);
switch (newState) {
case GST_WEBRTC_ICE_CONNECTION_STATE_NEW:
case GST_WEBRTC_ICE_CONNECTION_STATE_CHECKING:
instance->setState(CallSession::CONNECTING);
break;
case GST_WEBRTC_ICE_CONNECTION_STATE_FAILED:
instance->setState(CallSession::ICEFAILED);
break;
case GST_WEBRTC_ICE_CONNECTION_STATE_CONNECTED:
instance->setState(CallSession::CONNECTED);
case GST_WEBRTC_ICE_CONNECTION_STATE_COMPLETED:
case GST_WEBRTC_ICE_CONNECTION_STATE_DISCONNECTED:
case GST_WEBRTC_ICE_CONNECTION_STATE_CLOSED:
default:
break;
}
}
GstElement *newAudioSinkChain(GstElement *pipe)
{
qCWarning(voip) << "New Audio Sink Chain";
GstElement *queue = createElement("queue", pipe);
GstElement *convert = createElement("audioconvert", pipe);
GstElement *resample = createElement("audioresample", pipe);
GstElement *sink = createElement("autoaudiosink", pipe);
gst_element_link_many(queue, convert, resample, sink, nullptr);
gst_element_sync_state_with_parent(queue);
gst_element_sync_state_with_parent(convert);
gst_element_sync_state_with_parent(resample);
gst_element_sync_state_with_parent(sink);
return queue;
}
void sendKeyFrameRequest()
{
auto sinkpad = gst_element_get_static_pad(keyFrameRequestData.decodeBin, "sink");
if (!gst_pad_push_event(sinkpad, gst_event_new_custom(GST_EVENT_CUSTOM_UPSTREAM, gst_structure_new_empty("GstForceKeyUnit")))) {
qCWarning(voip) << "Keyframe request failed";
}
gst_object_unref(sinkpad);
}
void onGetStats(GstPromise *promise, gpointer)
{
auto reply = gst_promise_get_reply(promise);
GstStructure *rtpStats;
if (!gst_structure_get(reply, keyFrameRequestData.statsField.toLatin1().data(), GST_TYPE_STRUCTURE, &rtpStats, nullptr)) {
gst_promise_unref(promise);
return;
}
auto packetsLost = 0;
gst_structure_get_int(rtpStats, "packets-lost", &packetsLost);
gst_structure_free(rtpStats);
gst_promise_unref(promise);
if (packetsLost > keyFrameRequestData.packetsLost) {
qCWarning(voip) << "inbound video lost packet count:" << packetsLost;
keyFrameRequestData.packetsLost = packetsLost;
sendKeyFrameRequest();
}
}
// TODO port to QTimer?
gboolean testPacketLoss(gpointer)
{
if (!keyFrameRequestData.pipe) {
return false;
}
auto webrtc = binGetByName(keyFrameRequestData.pipe, "webrtcbin");
auto promise = gst_promise_new_with_change_func(onGetStats, nullptr, nullptr);
g_signal_emit_by_name(webrtc, "get-stats", nullptr, promise);
gst_object_unref(webrtc);
return true;
}
GstElement *newVideoSinkChain(GstElement *pipe, QQuickItem *quickItem)
{
Q_ASSERT(pipe);
Q_ASSERT(quickItem);
qCWarning(voip) << "Creating Video Sink Chain";
auto queue = createElement("queue", pipe);
auto compositor = createElement("compositor", pipe);
auto glupload = createElement("glupload", pipe);
auto glcolorconvert = createElement("glcolorconvert", pipe);
auto qmlglsink = createElement("qmlglsink", nullptr);
auto glsinkbin = createElement("glsinkbin", pipe);
g_object_set(qmlglsink, "widget", quickItem, nullptr);
g_object_set(glsinkbin, "sink", qmlglsink, nullptr);
gst_element_link_many(queue, compositor, glupload, glcolorconvert, glsinkbin, nullptr);
gst_element_sync_state_with_parent(queue);
gst_element_sync_state_with_parent(compositor);
gst_element_sync_state_with_parent(glupload);
gst_element_sync_state_with_parent(glcolorconvert);
gst_element_sync_state_with_parent(glsinkbin);
return queue;
}
static GstPadProbeReturn pad_cb(GstPad *pad, GstPadProbeInfo *info, gpointer user_data)
{
Q_UNUSED(pad);
// auto stream = static_cast<VideoStream *>(user_data);
auto event = GST_PAD_PROBE_INFO_EVENT(info);
if (GST_EVENT_CAPS == GST_EVENT_TYPE(event)) {
GstCaps *caps = gst_caps_new_any();
int width, height;
gst_event_parse_caps(event, &caps);
auto structure = gst_caps_get_structure(caps, 0);
gst_structure_get_int(structure, "width", &width);
gst_structure_get_int(structure, "height", &height);
// stream->setWidth(width);
// stream->setHeight(height);
// TODO needed?
}
return GST_PAD_PROBE_OK;
}
void linkNewPad(GstElement *decodeBin, GstPad *newpad, gpointer user_data)
{
INSTANCE
qCWarning(voip) << "Linking New Pad";
auto sinkpad = gst_element_get_static_pad(decodeBin, "sink");
auto sinkcaps = gst_pad_get_current_caps(sinkpad);
auto structure = gst_caps_get_structure(sinkcaps, 0);
gchar *mediaType = nullptr;
guint ssrc = 0;
gst_structure_get(structure, "media", G_TYPE_STRING, &mediaType, "ssrc", G_TYPE_UINT, &ssrc, nullptr);
gst_caps_unref(sinkcaps);
gst_object_unref(sinkpad);
GstElement *queue = nullptr;
if (!strcmp(mediaType, "audio")) {
qCWarning(voip) << "Receiving audio stream";
queue = newAudioSinkChain(instance->m_pipe);
} else if (!strcmp(mediaType, "video")) {
qCWarning(voip) << "Receiving video stream";
auto fake = createElement("fakesink", instance->m_pipe);
auto selector = createElement("output-selector", instance->m_pipe);
auto selectorSink = gst_element_get_static_pad(selector, "sink");
auto selectorSrc1 = gst_element_request_pad_simple(selector, "src_%u");
gst_pad_link(newpad, selectorSink);
auto fakepad = gst_element_get_static_pad(fake, "sink");
gst_pad_link(selectorSrc1, fakepad);
g_object_set(selector, "active-pad", selectorSrc1, nullptr);
auto msid = instance->ssrcToMsid[ssrc];
// gst_pad_add_probe(newpad, GST_PAD_PROBE_TYPE_EVENT_BOTH, pad_cb, stream, nullptr);
auto manager = dynamic_cast<CallManager *>(instance->parent());
auto participants = manager->callParticipants();
auto user = dynamic_cast<NeoChatUser *>(manager->room()->user(instance->msidToUserId[msid]));
participants->setHasCamera(user, true);
auto participant = participants->callParticipantForUser(user);
// gst_pad_add_probe(newpad, GST_PAD_PROBE_TYPE_EVENT_BOTH, pad_cb, nullptr, nullptr);
connectSingleShot(participant, &CallParticipant::initialized, instance, [=](QQuickItem *item) {
gst_pad_unlink(newpad, fakepad);
auto queue = newVideoSinkChain(instance->m_pipe, item);
auto queuepad = gst_element_get_static_pad(queue, "sink");
Q_ASSERT(queuepad);
auto selectorSrc = gst_element_request_pad_simple(selector, "src_%u");
auto ok = GST_PAD_LINK_SUCCESSFUL(gst_pad_link(selectorSrc, queuepad));
Q_ASSERT(ok);
g_object_set(selector, "active-pad", selectorSrc, nullptr);
instance->setState(CallSession::CONNECTED);
keyFrameRequestData.pipe = instance->m_pipe;
keyFrameRequestData.decodeBin = decodeBin;
keyFrameRequestData.timerId = g_timeout_add_seconds(3, testPacketLoss, nullptr);
keyFrameRequestData.statsField = QStringLiteral("rtp-inbound-stream-stats_") + QString::number(ssrc);
gst_object_unref(queuepad);
g_free(mediaType);
});
return;
} else {
g_free(mediaType);
qCWarning(voip) << "Unknown pad type:" << GST_PAD_NAME(newpad);
return;
}
auto queuepad = gst_element_get_static_pad(queue, "sink");
Q_ASSERT(queuepad);
auto ok = GST_PAD_LINK_SUCCESSFUL(gst_pad_link(newpad, queuepad));
Q_ASSERT(ok);
gst_object_unref(queuepad);
g_free(mediaType);
}
void setWaitForKeyFrame(GstBin *decodeBin, GstElement *element, gpointer)
{
Q_UNUSED(decodeBin);
if (!strcmp(gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(gst_element_get_factory(element))), "rtpvp8depay")) {
g_object_set(element, "wait-for-keyframe", TRUE, nullptr);
}
}
void addDecodeBin(GstElement *webrtc, GstPad *newpad, gpointer user_data)
{
Q_UNUSED(webrtc);
if (GST_PAD_DIRECTION(newpad) != GST_PAD_SRC) {
return;
}
INSTANCE
auto decodeBin = createElement("decodebin", instance->m_pipe);
// Investigate hardware, see nheko source
g_object_set(decodeBin, "force-sw-decoders", TRUE, nullptr);
g_signal_connect(decodeBin, "pad-added", G_CALLBACK(linkNewPad), instance);
g_signal_connect(decodeBin, "element-added", G_CALLBACK(setWaitForKeyFrame), nullptr);
gst_element_sync_state_with_parent(decodeBin);
auto sinkpad = gst_element_get_static_pad(decodeBin, "sink");
if (GST_PAD_LINK_FAILED(gst_pad_link(newpad, sinkpad))) {
// TODO: Error handling
qCWarning(voip) << "Unable to link decodebin";
}
gst_object_unref(sinkpad);
}
void iceGatheringStateChanged(GstElement *webrtc, GParamSpec *pspec, gpointer user_data)
{
Q_UNUSED(pspec);
INSTANCE
GstWebRTCICEGatheringState newState;
g_object_get(webrtc, "ice-gathering-state", &newState, nullptr);
if (newState == GST_WEBRTC_ICE_GATHERING_STATE_COMPLETE) {
qCWarning(voip) << "GstWebRTCICEGatheringState -> Complete";
if (instance->m_isOffering) {
Q_EMIT instance->offerCreated(instance->m_localSdp, instance->m_localCandidates);
instance->setState(CallSession::OFFERSENT);
} else {
Q_EMIT instance->answerCreated(instance->m_localSdp, instance->m_localCandidates);
instance->setState(CallSession::ANSWERSENT);
}
}
}
gboolean newBusMessage(GstBus *bus, GstMessage *msg, gpointer user_data)
{
Q_UNUSED(bus);
INSTANCE
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
qCWarning(voip) << "End of stream";
// TODO: Error handling
instance->end();
break;
case GST_MESSAGE_ERROR:
GError *error;
gchar *debug;
gst_message_parse_error(msg, &error, &debug);
qCWarning(voip) << "Error from element:" << GST_OBJECT_NAME(msg->src) << error->message;
// TODO: Error handling
g_clear_error(&error);
g_free(debug);
instance->end();
break;
default:
break;
}
return TRUE;
}
CallSession::CallSession(QObject *parent)
: QObject(parent)
{
}
void CallSession::acceptAnswer(const QString &sdp, const QVector<Candidate> &candidates, const QString &userId)
{
qCDebug(voip) << "Accepting Answer";
if (m_state != CallSession::OFFERSENT) {
return;
}
GstWebRTCSessionDescription *answer = parseSDP(sdp, GST_WEBRTC_SDP_TYPE_ANSWER);
if (!answer) {
end();
return;
}
acceptCandidates(candidates);
setRemoteDescription(answer, userId);
}
void CallSession::setRemoteDescription(GstWebRTCSessionDescription *remote, const QString &userId, GstPromise *promise)
{
GstElement *webrtcbin = binGetByName(m_pipe, "webrtcbin");
auto sdp = remote->sdp;
for (guint i = 0; i < gst_sdp_message_medias_len(sdp); i++) {
auto media = gst_sdp_message_get_media(sdp, i);
QList<uint32_t> ssrcs;
QString msid;
for (guint j = 0; j < gst_sdp_media_attributes_len(media); j++) {
auto attribute = gst_sdp_media_get_attribute(media, j);
if (!strcmp(attribute->key, "ssrc")) {
ssrcs += QString(attribute->value).split(" ")[0].toUInt();
}
if (!strcmp(attribute->key, "msid")) {
msid = QString(attribute->value).split(" ")[0];
}
}
for (const auto &ssrc : ssrcs) {
ssrcToMsid[ssrc] = msid;
}
msidToUserId[msid] = userId;
}
g_signal_emit_by_name(webrtcbin, "set-remote-description", remote, promise);
}
void CallSession::renegotiateOffer(const QString &_offer, const QString &userId, bool answer)
{
GstWebRTCSessionDescription *sdp = parseSDP(_offer, answer ? GST_WEBRTC_SDP_TYPE_ANSWER : GST_WEBRTC_SDP_TYPE_OFFER);
if (!sdp) {
Q_ASSERT(false);
}
GstElement *webrtcbin = binGetByName(m_pipe, "webrtcbin");
setRemoteDescription(sdp, userId);
qWarning() << "answer:" << answer;
if (!answer) {
GstPromise *promise = gst_promise_new_with_change_func(setLocalDescription, this, nullptr);
g_signal_emit_by_name(webrtcbin, "create-answer", nullptr, promise);
}
}
void CallSession::acceptOffer(const QString &sdp, const QVector<Candidate> remoteCandidates, const QString &userId)
{
Q_ASSERT(!sdp.isEmpty());
Q_ASSERT(!remoteCandidates.isEmpty());
qCDebug(voip) << "Accepting offer";
if (m_state != CallSession::DISCONNECTED) {
return;
}
m_isOffering = false;
GstWebRTCSessionDescription *offer = parseSDP(sdp, GST_WEBRTC_SDP_TYPE_OFFER);
if (!offer) {
qCCritical(voip) << "Not an offer";
return;
}
int opusPayloadType;
bool receiveOnly;
bool sendOnly;
if (getMediaAttributes(offer->sdp, "audio", "opus", opusPayloadType, receiveOnly, sendOnly)) {
if (opusPayloadType == -1) {
qCCritical(voip) << "No OPUS in offer";
gst_webrtc_session_description_free(offer);
return;
}
} else {
qCCritical(voip) << "No audio in offer";
gst_webrtc_session_description_free(offer);
return;
}
startPipeline();
QThread::msleep(1000); // ?
acceptCandidates(remoteCandidates);
auto promise = gst_promise_new_with_change_func(createAnswer, this, nullptr);
setRemoteDescription(offer, userId, promise);
gst_webrtc_session_description_free(offer);
}
void CallSession::createCall()
{
qCDebug(voip) << "Creating call";
m_isOffering = true;
startPipeline();
}
void CallSession::startPipeline()
{
qCDebug(voip) << "Starting Pipeline";
if (m_state != CallSession::DISCONNECTED) {
return;
}
m_state = CallSession::INITIATING;
Q_EMIT stateChanged();
createPipeline();
auto webrtcbin = binGetByName(m_pipe, "webrtcbin");
Q_ASSERT(webrtcbin);
if (false /*TODO: CHECK USE STUN*/) {
qCDebug(voip) << "Setting STUN server:" << STUN_SERVER;
g_object_set(webrtcbin, "stun-server", STUN_SERVER, nullptr);
}
for (const auto &uri : m_turnServers) {
qCDebug(voip) << "Setting turn server:" << uri;
gboolean udata;
g_signal_emit_by_name(webrtcbin, "add-turn-server", uri.toLatin1().data(), (gpointer)(&udata));
}
if (m_turnServers.empty()) {
qCWarning(voip) << "No TURN servers provided";
}
if (m_isOffering) {
g_signal_connect(webrtcbin, "on-negotiation-needed", G_CALLBACK(::createOffer), this);
}
g_signal_connect(webrtcbin, "on-ice-candidate", G_CALLBACK(addLocalICECandidate), this);
g_signal_connect(webrtcbin, "notify::ice-connection-state", G_CALLBACK(iceConnectionStateChanged), this);
gst_element_set_state(m_pipe, GST_STATE_READY);
g_signal_connect(webrtcbin, "pad-added", G_CALLBACK(addDecodeBin), this);
g_signal_connect(webrtcbin, "notify::ice-gathering-state", G_CALLBACK(iceGatheringStateChanged), this);
gst_object_unref(webrtcbin);
GstStateChangeReturn ret = gst_element_set_state(m_pipe, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
// TODO: Error handling
qCCritical(voip) << "Unable to start pipeline";
end();
return;
}
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(m_pipe));
m_busWatchId = gst_bus_add_watch(bus, newBusMessage, this);
gst_object_unref(bus);
m_state = CallSession::INITIATED;
Q_EMIT stateChanged();
}
void CallSession::end()
{
qCDebug(voip) << "Ending Call";
if (m_pipe) {
gst_element_set_state(m_pipe, GST_STATE_NULL);
gst_object_unref(m_pipe);
m_pipe = nullptr;
keyFrameRequestData.pipe = nullptr;
if (m_busWatchId) {
g_source_remove(m_busWatchId);
m_busWatchId = 0;
}
}
if (m_state != CallSession::DISCONNECTED) {
m_state = CallSession::DISCONNECTED;
Q_EMIT stateChanged();
}
}
void CallSession::createPipeline()
{
qCWarning(voip) << "Creating Pipeline";
auto device = AudioSources::instance().currentDevice();
if (!device) {
return;
}
m_pipe = gst_pipeline_new(nullptr);
auto source = gst_device_create_element(device, nullptr);
auto volume = createElement("volume", m_pipe, "srclevel");
auto convert = createElement("audioconvert", m_pipe);
auto resample = createElement("audioresample", m_pipe);
auto queue1 = createElement("queue", m_pipe);
auto opusenc = createElement("opusenc", m_pipe);
auto rtp = createElement("rtpopuspay", m_pipe);
auto queue2 = createElement("queue", m_pipe);
auto capsfilter = createElement("capsfilter", m_pipe);
auto rtpcaps = gst_caps_new_simple("application/x-rtp",
"media",
G_TYPE_STRING,
"audio",
"encoding-name",
G_TYPE_STRING,
"OPUS",
"payload",
G_TYPE_INT,
OPUS_PAYLOAD_TYPE,
nullptr);
Q_ASSERT(rtpcaps);
g_object_set(capsfilter, "caps", rtpcaps, nullptr);
gst_caps_unref(rtpcaps);
auto webrtcbin = createElement("webrtcbin", m_pipe, "webrtcbin");
g_object_set(webrtcbin, "bundle-policy", GST_WEBRTC_BUNDLE_POLICY_MAX_BUNDLE, nullptr);
gst_bin_add_many(GST_BIN(m_pipe), source, nullptr);
if (!gst_element_link_many(source, volume, convert, resample, queue1, opusenc, rtp, queue2, capsfilter, webrtcbin, nullptr)) {
qCCritical(voip) << "Failed to link pipeline";
// TODO propagate errors up and end call
return;
}
}
void CallSession::toggleCamera()
{
// TODO do this only once
static bool inited = false;
if (!inited) {
addVideoPipeline();
inited = true;
}
}
bool CallSession::addVideoPipeline()
{
qCDebug(voip) << "Adding Video Pipeline";
auto videoconvert = createElement("videoconvertscale", m_pipe);
auto tee = createElement("tee", m_pipe);
auto device = VideoSources::instance().currentDevice();
auto deviceCaps = device->caps[VideoSources::instance().capsIndex()];
int width = deviceCaps.width;
int height = deviceCaps.height;
int framerate = deviceCaps.framerates.back();
if (!device) {
return false;
}
auto camera = gst_device_create_element(device->device, nullptr);
gst_bin_add_many(GST_BIN(m_pipe), camera, nullptr);
auto caps =
gst_caps_new_simple("video/x-raw", "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, "framerate", GST_TYPE_FRACTION, framerate, 1, nullptr);
auto camerafilter = createElement("capsfilter", m_pipe);
g_object_set(camerafilter, "caps", caps, nullptr);
gst_caps_unref(caps);
gst_element_link(camera, videoconvert);
if (!gst_element_link_many(videoconvert, camerafilter, nullptr)) {
qCWarning(voip) << "Failed to link camera elements";
// TODO: Error handling
return false;
}
if (!gst_element_link(camerafilter, tee)) {
qCWarning(voip) << "Failed to link camerafilter -> tee";
// TODO: Error handling
return false;
}
auto queue = createElement("queue", m_pipe);
g_object_set(queue, "leaky", true, nullptr);
auto vp8enc = createElement("vp8enc", m_pipe);
g_object_set(vp8enc, "deadline", 1, nullptr);
g_object_set(vp8enc, "error-resilient", 1, nullptr);
auto rtpvp8pay = createElement("rtpvp8pay", m_pipe);
auto rtpqueue = createElement("queue", m_pipe);
auto rtpcapsfilter = createElement("capsfilter", m_pipe);
auto rtpcaps = gst_caps_new_simple("application/x-rtp",
"media",
G_TYPE_STRING,
"video",
"encoding-name",
G_TYPE_STRING,
"VP8",
"payload",
G_TYPE_INT,
VP8_PAYLOAD_TYPE,
nullptr);
g_object_set(rtpcapsfilter, "caps", rtpcaps, nullptr);
gst_caps_unref(rtpcaps);
auto webrtcbin = binGetByName(m_pipe, "webrtcbin");
if (!gst_element_link_many(tee, queue, vp8enc, rtpvp8pay, rtpqueue, rtpcapsfilter, webrtcbin, nullptr)) {
qCCritical(voip) << "Failed to link rtp video elements";
gst_object_unref(webrtcbin);
return false;
}
auto promise = gst_promise_new_with_change_func(setLocalDescription, this, nullptr);
g_signal_emit_by_name(webrtcbin, "create-offer", nullptr, promise);
gst_object_unref(webrtcbin);
auto newpad = gst_element_request_pad_simple(tee, "src_%u");
Q_ASSERT(newpad);
auto fake = createElement("fakesink", m_pipe);
auto selector = createElement("output-selector", m_pipe);
auto selectorSink = gst_element_get_static_pad(selector, "sink");
auto selectorSrc1 = gst_element_request_pad_simple(selector, "src_%u");
gst_pad_link(newpad, selectorSink);
auto fakepad = gst_element_get_static_pad(fake, "sink");
gst_pad_link(selectorSrc1, fakepad);
g_object_set(selector, "active-pad", selectorSrc1, nullptr);
// gst_pad_add_probe(newpad, GST_PAD_PROBE_TYPE_EVENT_BOTH, pad_cb, stream, nullptr);
auto manager = dynamic_cast<CallManager *>(parent());
auto participants = manager->callParticipants();
auto user = dynamic_cast<NeoChatUser *>(manager->room()->localUser());
participants->setHasCamera(user, true);
connectSingleShot(participants->callParticipantForUser(user), &CallParticipant::initialized, this, [=](QQuickItem *item) {
gst_pad_unlink(newpad, fakepad);
Q_ASSERT(item);
auto queue = newVideoSinkChain(m_pipe, item);
Q_ASSERT(queue);
auto queuepad = gst_element_get_static_pad(queue, "sink");
Q_ASSERT(queuepad);
auto selectorSrc = gst_element_request_pad_simple(selector, "src_%u");
Q_ASSERT(selectorSrc);
auto ok = GST_PAD_LINK_SUCCESSFUL(gst_pad_link(selectorSrc, queuepad));
Q_ASSERT(ok);
g_object_set(selector, "active-pad", selectorSrc, nullptr);
gst_object_unref(queuepad);
gst_element_set_state(m_pipe, GST_STATE_READY); // TODO experimental
gst_element_set_state(m_pipe, GST_STATE_PLAYING); // TODO experimental
GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(m_pipe), GST_DEBUG_GRAPH_SHOW_ALL, "foo");
});
return true;
}
void CallSession::setTurnServers(QStringList servers)
{
qCDebug(voip) << "Setting Turn Servers";
qWarning() << "TURN SERVERS" << servers;
m_turnServers = servers;
}
void CallSession::acceptCandidates(const QVector<Candidate> &candidates)
{
qCDebug(voip) << "Accepting ICE Candidates";
auto webrtcbin = binGetByName(m_pipe, "webrtcbin");
for (const auto &c : candidates) {
qCDebug(voip) << "Remote candidate:" << c.candidate << c.sdpMLineIndex;
g_signal_emit_by_name(webrtcbin, "add-ice-candidate", c.sdpMLineIndex, c.candidate.toLatin1().data());
}
}
QStringList CallSession::missingPlugins()
{
GstRegistry *registry = gst_registry_get();
static const QVector<QString> videoPlugins = {
QLatin1String("compositor"),
QLatin1String("opengl"),
QLatin1String("qmlgl"),
QLatin1String("rtp"),
QLatin1String("videoconvertscale"),
QLatin1String("vpx"),
};
static const QVector<QString> audioPlugins = {
QStringLiteral("audioconvert"),
QStringLiteral("audioresample"),
QStringLiteral("autodetect"),
QStringLiteral("dtls"),
QStringLiteral("nice"),
QStringLiteral("opus"),
QStringLiteral("playback"),
QStringLiteral("rtpmanager"),
QStringLiteral("srtp"),
QStringLiteral("volume"),
QStringLiteral("webrtc"),
};
QStringList missingPlugins;
for (const auto &pluginName : videoPlugins + audioPlugins) {
auto plugin = gst_registry_find_plugin(registry, pluginName.toLatin1().data());
if (!plugin) {
missingPlugins << pluginName;
}
gst_object_unref(plugin);
}
return missingPlugins;
}
void CallSession::setMuted(bool muted)
{
const auto srclevel = binGetByName(m_pipe, "srclevel");
g_object_set(srclevel, "mute", muted, nullptr);
gst_object_unref(srclevel);
Q_EMIT mutedChanged();
}
bool CallSession::muted() const
{
if (m_state < CallSession::CONNECTING) {
return false;
}
if (!m_pipe) {
return false;
}
const auto srclevel = binGetByName(m_pipe, "srclevel");
bool muted;
if (!srclevel) {
return false;
}
g_object_get(srclevel, "mute", &muted, nullptr);
// gst_object_unref(srclevel); //TODO why does this crash?
return muted;
}
CallSession *
CallSession::acceptCall(const QString &sdp, const QVector<Candidate> &candidates, const QStringList &turnUris, const QString &userId, QObject *parent)
{
auto instance = new CallSession(parent);
instance->setTurnServers(turnUris);
instance->acceptOffer(sdp, candidates, userId);
return instance;
}
CallSession *CallSession::startCall(const QStringList &turnUris, QObject *parent)
{
auto instance = new CallSession(parent);
instance->setTurnServers(turnUris);
instance->createCall();
return instance;
}
CallSession::State CallSession::state() const
{
return m_state;
}
void CallSession::setState(CallSession::State state)
{
qCWarning(voip) << "Setting state" << state;
m_state = state;
Q_EMIT stateChanged();
}
void CallSession::setMetadata(QJsonObject metadata)
{
m_metadata = metadata;
}

113
src/call/callsession.h Normal file
View File

@@ -0,0 +1,113 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
// SPDX-FileCopyrightText: 2021-2022 Tobias Fella <fella@posteo.de>
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <QJsonObject>
#include <QMetaType>
#include <QObject>
#include <QQuickItem>
#include <QString>
#include <variant>
#define GST_USE_UNSTABLE_API
#include <gst/webrtc/webrtc.h>
#include <gst/gst.h>
#define OPUS_PAYLOAD_TYPE 111
#define VP8_PAYLOAD_TYPE 96
class CallDevices;
class VideoStream;
struct Candidate {
QString candidate;
int sdpMLineIndex;
QString sdpMid;
};
Q_DECLARE_METATYPE(Candidate)
Q_DECLARE_METATYPE(QVector<Candidate>)
class CallSession : public QObject
{
Q_OBJECT
public:
enum State {
DISCONNECTED,
ICEFAILED,
INITIATING,
INITIATED,
OFFERSENT,
ANSWERSENT,
CONNECTING,
CONNECTED,
};
Q_ENUM(State);
Q_PROPERTY(CallSession::State state READ state NOTIFY stateChanged)
Q_PROPERTY(bool muted READ muted WRITE setMuted NOTIFY mutedChanged)
// For outgoing calls
static CallSession *startCall(const QStringList &turnUris, QObject *parent = nullptr);
void acceptAnswer(const QString &sdp, const QVector<Candidate> &candidates, const QString &parent);
// For incoming calls
static CallSession *
acceptCall(const QString &sdp, const QVector<Candidate> &candidates, const QStringList &turnUris, const QString &userId, QObject *parent = nullptr);
void end();
void renegotiateOffer(const QString &offer, const QString &userId, bool answer);
void setTurnServers(QStringList servers);
static QStringList missingPlugins();
CallSession::State state() const;
void toggleCamera();
bool muted() const;
void setMuted(bool muted);
void setMetadata(QJsonObject metadata);
void acceptCandidates(const QVector<Candidate> &candidates);
QMap<QString, QString> msidToUserId;
Q_SIGNALS:
void stateChanged();
void offerCreated(const QString &sdp, const QVector<Candidate> &candidates);
void answerCreated(const QString &sdp, const QVector<Candidate> &candidates);
void mutedChanged();
void newVideoStream(VideoStream *stream);
void renegotiate(QString sdp, const QString &type);
private:
CallSession(QObject *parent = nullptr);
void acceptOffer(const QString &sdp, const QVector<Candidate> remoteCandidates, const QString &userId);
void createCall();
void setRemoteDescription(GstWebRTCSessionDescription *remote, const QString &userId, GstPromise *promise = nullptr);
void startPipeline();
void createPipeline();
bool addVideoPipeline();
void setState(CallSession::State state);
GstPad *m_activePad;
GstElement *m_inputSelector;
CallSession::State m_state = CallSession::DISCONNECTED;
unsigned int m_busWatchId = 0;
QStringList m_turnServers;
QVector<Candidate> m_localCandidates;
QString m_localSdp;
GstElement *m_pipe = nullptr;
bool m_isOffering = false;
QMap<int, QString> ssrcToMsid;
QJsonObject m_metadata;
GstPad *m_inactivePad;
};

165
src/call/devicemonitor.cpp Normal file
View File

@@ -0,0 +1,165 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "devicemonitor.h"
#include "voiplogging.h"
#include <QTimer>
QDebug operator<<(QDebug dbg, const GstStructure *props)
{
QDebugStateSaver saver(dbg);
auto asStr = gst_structure_to_string(props);
dbg << asStr;
g_free(asStr);
return dbg;
}
static gboolean deviceCallback(GstBus *bus, GstMessage *message, gpointer user_data)
{
Q_UNUSED(bus);
auto monitor = static_cast<DeviceMonitor *>(user_data);
return monitor->callback(message);
}
DeviceMonitor::DeviceMonitor()
: QObject()
{
QTimer::singleShot(0, this, &DeviceMonitor::init);
}
void DeviceMonitor::init()
{
if (m_monitor) {
return;
}
m_monitor = gst_device_monitor_new();
GstCaps *caps = gst_caps_new_empty_simple("audio/x-raw");
gst_device_monitor_add_filter(m_monitor, "Audio/Source", caps);
gst_caps_unref(caps);
caps = gst_caps_new_empty_simple("video/x-raw");
gst_device_monitor_add_filter(m_monitor, "Video/Source", caps);
gst_caps_unref(caps);
GstBus *bus = gst_device_monitor_get_bus(m_monitor);
gst_bus_add_watch(bus, deviceCallback, this);
gst_object_unref(bus);
if (!gst_device_monitor_start(m_monitor)) {
qWarning() << "Failed to start device monitor";
}
}
QVector<AudioSource *> DeviceMonitor::audioSources() const
{
return m_audioSources;
}
QVector<VideoSource *> DeviceMonitor::videoSources() const
{
return m_videoSources;
}
void DeviceMonitor::handleVideoSource(GstDevice *device)
{
auto source = new VideoSource();
auto title = gst_device_get_display_name(device);
source->title = QString(title);
g_free(title);
source->device = device;
auto caps = gst_device_get_caps(device);
auto size = gst_caps_get_size(caps);
for (size_t i = 0; i < size; i++) {
VideoCap videoCap;
GstStructure *cap = gst_caps_get_structure(caps, i);
const gchar *name = gst_structure_get_name(cap);
if (strcmp(name, "video/x-raw")) {
// TODO g_free(name);
continue;
}
// TODO g_free(name);
gst_structure_get(cap, "width", G_TYPE_INT, &videoCap.width, "height", G_TYPE_INT, &videoCap.height, nullptr);
const auto framerate = gst_structure_get_value(cap, "framerate");
if (GST_VALUE_HOLDS_FRACTION(framerate)) {
auto numerator = gst_value_get_fraction_numerator(framerate);
auto denominator = gst_value_get_fraction_denominator(framerate);
videoCap.framerates += (float)numerator / denominator;
}
// unref cap?
source->caps += videoCap;
}
m_videoSources += source;
Q_EMIT videoSourceAdded();
}
void DeviceMonitor::handleAudioSource(GstDevice *device)
{
auto source = new AudioSource();
auto title = gst_device_get_display_name(device);
source->title = QString(title);
g_free(title);
GstStructure *props = gst_device_get_properties(device);
gboolean isDefault = false;
if (gst_structure_has_field(props, "is-default")) {
gst_structure_get_boolean(props, "is-default", &isDefault);
}
gst_structure_free(props);
source->isDefault = isDefault;
source->device = device;
m_audioSources += source;
Q_EMIT audioSourceAdded();
}
bool DeviceMonitor::callback(GstMessage *message)
{
GstDevice *device;
switch (GST_MESSAGE_TYPE(message)) {
case GST_MESSAGE_DEVICE_ADDED: {
gst_message_parse_device_added(message, &device);
auto name = gst_device_get_display_name(device);
auto props = gst_device_get_properties(device);
qCDebug(voip) << name << props;
gst_structure_free(props);
if (gst_device_has_classes(device, "Video/Source")) {
handleVideoSource(device);
} else if (gst_device_has_classes(device, "Audio/Source")) {
handleAudioSource(device);
}
g_free(name);
gst_object_unref(device);
break;
}
case GST_MESSAGE_DEVICE_REMOVED: {
gst_message_parse_device_removed(message, &device);
auto name = gst_device_get_display_name(device);
auto props = gst_device_get_properties(device);
qCDebug(voip) << name << props;
if (gst_device_has_classes(device, "Video/Source")) {
m_videoSources.erase(std::remove_if(m_videoSources.begin(),
m_videoSources.end(),
[name](auto d) {
return d->title == QString(name);
}),
m_videoSources.end());
Q_EMIT videoSourceRemoved();
} else if (gst_device_has_classes(device, "Audio/Source")) {
m_audioSources.erase(std::remove_if(m_audioSources.begin(),
m_audioSources.end(),
[name](auto d) {
return d->title == QString(name);
}),
m_audioSources.end());
Q_EMIT audioSourceRemoved();
}
g_free(name);
gst_object_unref(device);
break;
}
default:
break;
}
return G_SOURCE_CONTINUE;
}

59
src/call/devicemonitor.h Normal file
View File

@@ -0,0 +1,59 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <QtCore/QDebug>
#include <QtCore/QObject>
#include <QtCore/QVector>
#include <gst/gst.h>
struct AudioSource {
QString title;
GstDevice *device;
bool isDefault;
};
struct VideoCap {
int width;
int height;
QVector<float> framerates;
};
struct VideoSource {
QString title;
GstDevice *device;
QVector<VideoCap> caps;
};
class DeviceMonitor : public QObject
{
Q_OBJECT
public:
static DeviceMonitor &instance()
{
static DeviceMonitor _instance;
return _instance;
}
QVector<AudioSource *> audioSources() const;
QVector<VideoSource *> videoSources() const;
bool callback(GstMessage *message);
void init();
Q_SIGNALS:
void videoSourceAdded();
void audioSourceAdded();
void videoSourceRemoved();
void audioSourceRemoved();
private:
DeviceMonitor();
GstDeviceMonitor *m_monitor = nullptr;
QVector<AudioSource *> m_audioSources;
QVector<VideoSource *> m_videoSources;
void handleVideoSource(GstDevice *device);
void handleAudioSource(GstDevice *device);
};

142
src/call/videosources.cpp Normal file
View File

@@ -0,0 +1,142 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "videosources.h"
#include <gst/gst.h>
// #include "pipelinemanager.h"
#include <QDebug>
#include <QString>
#include "devicemonitor.h"
#include "neochatconfig.h"
int VideoSources::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return DeviceMonitor::instance().videoSources().size();
}
QVariant VideoSources::data(const QModelIndex &index, int role) const
{
if (index.row() >= DeviceMonitor::instance().videoSources().size()) {
return QVariant(QStringLiteral("DEADBEEF"));
}
if (role == TitleRole) {
return DeviceMonitor::instance().videoSources()[index.row()]->title;
}
return QVariant();
}
QHash<int, QByteArray> VideoSources::roleNames() const
{
return {
{TitleRole, "title"},
};
}
VideoSources::VideoSources()
: QAbstractListModel()
{
connect(&DeviceMonitor::instance(), &DeviceMonitor::videoSourceAdded, this, [this]() {
beginResetModel();
endResetModel();
Q_EMIT currentIndexChanged();
});
connect(&DeviceMonitor::instance(), &DeviceMonitor::videoSourceRemoved, this, [this]() {
beginResetModel();
endResetModel();
Q_EMIT currentIndexChanged();
});
}
void VideoSources::foo(int index)
{
auto device = DeviceMonitor::instance().videoSources()[index]->device;
auto bin = gst_bin_new(nullptr);
GstElement *videoconvert = gst_element_factory_make("videoconvert", nullptr);
// GstElement *videorate = gst_element_factory_make("videorate", nullptr);
GstElement *filter = gst_element_factory_make("capsfilter", nullptr);
GstCaps *caps = gst_caps_new_simple("video/x-raw", "width", G_TYPE_INT, 1920, "height", G_TYPE_INT, 1080, "framerate", GST_TYPE_FRACTION, 5, 1, nullptr);
g_object_set(filter, "caps", caps, nullptr);
gst_caps_unref(caps);
GstElement *deviceElement = gst_device_create_element(device, nullptr);
gst_bin_add_many(GST_BIN(bin), deviceElement, videoconvert, filter, nullptr);
gst_element_link_many(deviceElement, videoconvert, filter, nullptr);
// GstPad *pad = gst_element_get_static_pad(filter, "src");
GstPad *pad = gst_element_get_static_pad(filter, "src");
auto ghostpad = gst_ghost_pad_new("src", pad);
gst_element_add_pad(bin, ghostpad);
gst_object_unref(pad);
// PipelineManager::instance().add(bin);
}
const VideoSource *VideoSources::currentDevice() const
{
const auto config = NeoChatConfig::self();
const QString name = config->camera();
for (const auto &videoSource : DeviceMonitor::instance().videoSources()) {
if (videoSource->title == name) {
qDebug() << "WebRTC: camera:" << name;
return videoSource;
}
}
if (DeviceMonitor::instance().videoSources().length() == 0) {
return nullptr;
}
return DeviceMonitor::instance().videoSources()[0];
}
void VideoSources::setCurrentIndex(int index)
{
if (DeviceMonitor::instance().videoSources().size() == 0) {
return;
}
NeoChatConfig::setCamera(DeviceMonitor::instance().videoSources()[index]->title);
NeoChatConfig::self()->save();
setCapsIndex(0);
}
int VideoSources::currentIndex() const
{
const auto config = NeoChatConfig::self();
const QString name = config->camera();
for (auto i = 0; i < DeviceMonitor::instance().videoSources().size(); i++) {
if (DeviceMonitor::instance().videoSources()[i]->title == name) {
return i;
}
}
return 0;
}
QStringList VideoSources::caps(int index) const
{
if (index >= DeviceMonitor::instance().videoSources().size()) {
return QStringList();
}
const auto &caps = DeviceMonitor::instance().videoSources()[index]->caps;
QStringList strings;
for (const auto &cap : caps) {
strings += QStringLiteral("%1x%2, %3 FPS").arg(cap.width).arg(cap.height).arg(cap.framerates.back());
}
return strings;
}
void VideoSources::setCapsIndex(int index)
{
NeoChatConfig::self()->setCameraCaps(index);
NeoChatConfig::self()->save();
Q_EMIT capsIndexChanged();
}
int VideoSources::capsIndex() const
{
return NeoChatConfig::self()->cameraCaps();
}

51
src/call/videosources.h Normal file
View File

@@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <QtCore/QAbstractListModel>
#include <gst/gst.h>
#include "devicemonitor.h"
class VideoSources : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
Q_PROPERTY(int capsIndex READ capsIndex WRITE setCapsIndex NOTIFY capsIndexChanged)
public:
enum Roles {
TitleRole = Qt::UserRole + 1,
DeviceRole,
};
static VideoSources &instance()
{
static VideoSources _instance;
return _instance;
}
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE void foo(int index);
const VideoSource *currentDevice() const;
void setCurrentIndex(int index);
int currentIndex() const;
void setCapsIndex(int index);
int capsIndex() const;
Q_INVOKABLE QStringList caps(int index) const;
Q_SIGNALS:
void currentIndexChanged();
void capsIndexChanged();
private:
VideoSources();
};

View File

@@ -14,6 +14,8 @@
#include <Sonnet/BackgroundChecker>
#include <Sonnet/Settings>
#include "neochatroom.h"
class SyntaxHighlighter : public QSyntaxHighlighter
{
public:
@@ -353,5 +355,3 @@ void ChatDocumentHandler::setErrorColor(const QColor &color)
m_highlighter->rehighlight();
Q_EMIT errorColorChanged();
}
#include "moc_chatdocumenthandler.cpp"

View File

@@ -79,5 +79,3 @@ void Clipboard::setImage(const QUrl &url)
}
}
}
#include "moc_clipboard.cpp"

View File

@@ -44,5 +44,3 @@ QString ColorSchemer::nameForIndex(int index) const
{
return c->model()->data(c->model()->index(index, 0), Qt::DisplayRole).toString();
}
#include "moc_colorschemer.cpp"

View File

@@ -28,7 +28,7 @@ class ColorSchemer : public QObject
Q_PROPERTY(QAbstractItemModel *model READ model CONSTANT)
public:
explicit ColorSchemer(QObject *parent = nullptr);
ColorSchemer(QObject *parent = nullptr);
~ColorSchemer();
QAbstractItemModel *model() const;

View File

@@ -31,15 +31,22 @@
#include <signal.h>
#include <Quotient/accountregistry.h>
#include <Quotient/connection.h>
#include <Quotient/csapi/content-repo.h>
#include <Quotient/csapi/logout.h>
#include <Quotient/csapi/profile.h>
#include <Quotient/jobs/downloadfilejob.h>
#include <Quotient/qt_connection_util.h>
#include <Quotient/csapi/notifications.h>
#include <Quotient/eventstats.h>
#ifdef QUOTIENT_07
#include "accountregistry.h"
#else
#include "neochataccountregistry.h"
#endif
#include <connection.h>
#include <csapi/content-repo.h>
#include <csapi/logout.h>
#include <csapi/profile.h>
#include <jobs/downloadfilejob.h>
#include <qt_connection_util.h>
#ifdef QUOTIENT_07
#include <eventstats.h>
#endif
#include "neochatconfig.h"
#include "neochatroom.h"
@@ -101,22 +108,24 @@ Controller::Controller(QObject *parent)
}
#endif
connect(&m_accountRegistry, &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged);
#ifdef QUOTIENT_07
connect(&Accounts, &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged);
#else
connect(&AccountRegistry::instance(), &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged);
#endif
#ifdef QUOTIENT_07
static int oldAccountCount = 0;
connect(&m_accountRegistry, &AccountRegistry::accountCountChanged, this, [this]() {
if (m_accountRegistry.size() > oldAccountCount) {
auto connection = m_accountRegistry.accounts()[m_accountRegistry.size() - 1];
connect(&Accounts, &AccountRegistry::accountCountChanged, this, [this]() {
if (Accounts.size() > oldAccountCount) {
auto connection = Accounts.accounts()[Accounts.size() - 1];
connect(connection, &Connection::syncDone, this, [connection]() {
NotificationsManager::instance().handleNotifications(connection);
});
}
oldAccountCount = m_accountRegistry.size();
});
QTimer::singleShot(0, this, [this] {
m_pushRuleModel = new PushRuleModel;
oldAccountCount = Accounts.size();
});
#endif
}
Controller &Controller::instance()
@@ -147,10 +156,18 @@ void Controller::logout(Connection *conn, bool serverSideLogout)
job.start();
loop.exec();
if (m_accountRegistry.count() > 1) {
#ifdef QUOTIENT_07
if (Accounts.count() > 1) {
#else
if (AccountRegistry::instance().count() > 1) {
#endif
// Only set the connection if the the account being logged out is currently active
if (conn == activeConnection()) {
setActiveConnection(m_accountRegistry.accounts()[0]);
#ifdef QUOTIENT_07
setActiveConnection(Accounts.accounts()[0]);
#else
setActiveConnection(AccountRegistry::instance().accounts()[0]);
#endif
}
} else {
setActiveConnection(nullptr);
@@ -165,7 +182,11 @@ void Controller::addConnection(Connection *c)
{
Q_ASSERT_X(c, __FUNCTION__, "Attempt to add a null connection");
m_accountRegistry.add(c);
#ifdef QUOTIENT_07
Accounts.add(c);
#else
AccountRegistry::instance().add(c);
#endif
c->setLazyLoading(true);
@@ -180,7 +201,7 @@ void Controller::addConnection(Connection *c)
});
connect(c, &Connection::requestFailed, this, [this](BaseJob *job) {
if (job->error() == BaseJob::UserConsentRequired) {
if (job->error() == BaseJob::UserConsentRequiredError) {
Q_EMIT userConsentRequired(job->errorUrl());
}
});
@@ -195,8 +216,15 @@ void Controller::dropConnection(Connection *c)
{
Q_ASSERT_X(c, __FUNCTION__, "Attempt to drop a null connection");
#ifndef QUOTIENT_07
AccountRegistry::instance().drop(c);
#endif
Q_EMIT connectionDropped(c);
Q_EMIT accountCountChanged();
#ifndef QUOTIENT_07
c->deleteLater();
#endif
}
void Controller::invokeLogin()
@@ -247,7 +275,7 @@ void Controller::invokeLogin()
connect(connection, &Connection::networkError, this, [this](const QString &error, const QString &, int, int) {
Q_EMIT errorOccured(i18n("Network Error: %1", error));
});
connection->assumeIdentity(account.userId(), accessToken);
connection->assumeIdentity(account.userId(), accessToken, account.deviceId());
});
}
}
@@ -263,7 +291,7 @@ QKeychain::ReadPasswordJob *Controller::loadAccessTokenFromKeyChain(const Accoun
job->setKey(account.userId());
// Handling of errors
connect(job, &QKeychain::Job::finished, this, [this, job]() {
connect(job, &QKeychain::Job::finished, this, [this, &account, job]() {
if (job->error() == QKeychain::Error::NoError) {
return;
}
@@ -369,7 +397,11 @@ bool Controller::setAvatar(Connection *connection, const QUrl &avatarSource)
User *localUser = connection->user();
QString decoded = avatarSource.path();
if (decoded.isEmpty()) {
#ifdef QUOTIENT_07
connection->callApi<SetAvatarUrlJob>(localUser->id(), avatarSource);
#else
connection->callApi<SetAvatarUrlJob>(localUser->id(), QString());
#endif
return true;
}
if (QImageReader(decoded).read().isNull()) {
@@ -380,7 +412,11 @@ bool Controller::setAvatar(Connection *connection, const QUrl &avatarSource)
}
NeochatChangePasswordJob::NeochatChangePasswordJob(const QString &newPassword, bool logoutDevices, const Omittable<QJsonObject> &auth)
#ifdef QUOTIENT_07
: BaseJob(HttpVerb::Post, QStringLiteral("ChangePasswordJob"), "/_matrix/client/r0/account/password")
#else
: BaseJob(HttpVerb::Post, QStringLiteral("ChangePasswordJob"), QStringLiteral("/_matrix/client/r0/account/password"))
#endif
{
QJsonObject _data;
addParam<>(_data, QStringLiteral("new_password"), newPassword);
@@ -391,7 +427,11 @@ NeochatChangePasswordJob::NeochatChangePasswordJob(const QString &newPassword, b
int Controller::accountCount() const
{
return m_accountRegistry.count();
#ifdef QUOTIENT_07
return Accounts.count();
#else
return AccountRegistry::instance().count();
#endif
}
void Controller::setQuitOnLastWindowClosed()
@@ -467,18 +507,17 @@ void Controller::setActiveConnection(Connection *connection)
Q_EMIT activeAccountLabelChanged();
}
PushRuleModel *Controller::pushRuleModel() const
{
return m_pushRuleModel;
}
void Controller::saveWindowGeometry()
{
WindowController::instance().saveGeometry();
}
NeochatDeleteDeviceJob::NeochatDeleteDeviceJob(const QString &deviceId, const Omittable<QJsonObject> &auth)
#ifdef QUOTIENT_07
: Quotient::BaseJob(HttpVerb::Delete, QStringLiteral("DeleteDeviceJob"), QStringLiteral("/_matrix/client/r0/devices/%1").arg(deviceId).toLatin1())
#else
: Quotient::BaseJob(HttpVerb::Delete, QStringLiteral("DeleteDeviceJob"), QStringLiteral("/_matrix/client/r0/devices/%1").arg(deviceId))
#endif
{
QJsonObject _data;
addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth);
@@ -584,7 +623,11 @@ bool Controller::hasWindowSystem() const
bool Controller::encryptionSupported() const
{
#ifdef QUOTIENT_07
return Quotient::encryptionSupported();
#else
return false;
#endif
}
void Controller::forceRefreshTextDocument(QQuickTextDocument *textDocument, QQuickItem *item)
@@ -625,16 +668,29 @@ void Controller::setApplicationProxy()
int Controller::activeConnectionIndex() const
{
auto result = std::find_if(m_accountRegistry.accounts().begin(), m_accountRegistry.accounts().end(), [this](const auto &it) {
#ifdef QUOTIENT_07
auto result = std::find_if(Accounts.accounts().begin(), Accounts.accounts().end(), [this](const auto &it) {
return it == m_connection;
});
return result - m_accountRegistry.accounts().begin();
return result - Accounts.accounts().begin();
#else
for (int i = 0; i < AccountRegistry::instance().rowCount(); i++) {
if (AccountRegistry::instance().data(AccountRegistry::instance().index(i, 0), AccountRegistry::UserIdRole).toString() == m_connection->userId()) {
return i;
}
}
return 0;
#endif
}
int Controller::quotientMinorVersion() const
{
// TODO libQuotient 0.7: Replace with version function from libQuotient
// TODO libQuotient 0.7: Replace with version function from libQuotient
#ifdef QUOTIENT_07
return 7;
#else
return 6;
#endif
}
bool Controller::isFlatpak() const
@@ -681,9 +737,11 @@ QVariantList Controller::getSupportedRoomVersions(Quotient::Connection *connecti
return supportedRoomVersions;
}
AccountRegistry &Controller::accounts()
bool Controller::callsSupported() const
{
return m_accountRegistry;
#ifdef GSTREAMER_AVAILABLE
return true;
#else
return false;
#endif
}
#include "moc_controller.cpp"

View File

@@ -3,15 +3,13 @@
#pragma once
#include "models/pushrulemodel.h"
#include <QObject>
#include <QQuickItem>
#include <KFormat>
#include <Quotient/accountregistry.h>
#include <Quotient/jobs/basejob.h>
#include <Quotient/settings.h>
#include <jobs/basejob.h>
#include <settings.h>
class NeoChatRoom;
class NeoChatUser;
@@ -52,11 +50,6 @@ class Controller : public QObject
*/
Q_PROPERTY(Quotient::Connection *activeConnection READ activeConnection WRITE setActiveConnection NOTIFY activeConnectionChanged)
/**
* @brief The PushRuleModel that has the active connection's push rules.
*/
Q_PROPERTY(PushRuleModel *pushRuleModel READ pushRuleModel CONSTANT)
/**
* @brief The row number in the accounts directory of the active connection.
*/
@@ -107,6 +100,7 @@ class Controller : public QObject
* This is the only way to gate NeoChat features in flatpaks in QML.
*/
Q_PROPERTY(bool isFlatpak READ isFlatpak CONSTANT)
Q_PROPERTY(bool callsSupported READ callsSupported CONSTANT)
public:
/**
@@ -117,7 +111,7 @@ public:
Wrong, /**< The current password entered was wrong. */
Other, /**< An unknown problem occurred. */
};
Q_ENUM(PasswordStatus)
Q_ENUM(PasswordStatus);
static Controller &instance();
@@ -126,8 +120,6 @@ public:
void setActiveConnection(Quotient::Connection *connection);
[[nodiscard]] Quotient::Connection *activeConnection() const;
[[nodiscard]] PushRuleModel *pushRuleModel() const;
/**
* @brief Add a new connection to the account registry.
*/
@@ -206,6 +198,7 @@ public:
int quotientMinorVersion() const;
bool isFlatpak() const;
bool callsSupported() const;
/**
* @brief Return a string for the input timestamp.
@@ -230,8 +223,6 @@ public:
Q_INVOKABLE QVariantList getSupportedRoomVersions(Quotient::Connection *connection);
Quotient::AccountRegistry &accounts();
private:
explicit Controller(QObject *parent = nullptr);
@@ -247,9 +238,6 @@ private:
bool hasWindowSystem() const;
QPointer<PushRuleModel> m_pushRuleModel;
Quotient::AccountRegistry m_accountRegistry;
private Q_SLOTS:
void invokeLogin();
void showWindow();

View File

@@ -151,5 +151,3 @@ qreal DelegateSizeHelper::currentWidth() const
return std::ceil(std::min(absoluteWidth, m_maxWidth));
}
}
#include "moc_delegatesizehelper.cpp"

View File

@@ -77,7 +77,7 @@ class DelegateSizeHelper : public QObject
Q_PROPERTY(qreal currentWidth READ currentWidth NOTIFY currentWidthChanged)
public:
explicit DelegateSizeHelper(QObject *parent = nullptr);
DelegateSizeHelper(QObject *parent = nullptr);
qreal parentWidth() const;
void setParentWidth(qreal parentWidth);

View File

@@ -11,7 +11,11 @@ ImagePackEventContent::ImagePackEventContent(const QJsonObject &json)
if (json.contains(QStringLiteral("pack"))) {
pack = ImagePackEventContent::Pack{
fromJson<Omittable<QString>>(json["pack"].toObject()["display_name"]),
#ifdef QUOTIENT_07
fromJson<Omittable<QUrl>>(json["pack"].toObject()["avatar_url"]),
#else
QUrl(),
#endif
fromJson<Omittable<QStringList>>(json["pack"].toObject()["usage"]),
fromJson<Omittable<QString>>(json["pack"].toObject()["attribution"]),
};
@@ -23,13 +27,21 @@ ImagePackEventContent::ImagePackEventContent(const QJsonObject &json)
for (const auto &k : keys) {
Omittable<EventContent::ImageInfo> info;
if (json["images"][k].toObject().contains(QStringLiteral("info"))) {
#ifdef QUOTIENT_07
info = EventContent::ImageInfo(QUrl(json["images"][k]["url"].toString()), json["images"][k]["info"].toObject(), k);
#else
info = EventContent::ImageInfo(QUrl(json["images"][k]["url"].toString()), json["images"][k].toObject(), k);
#endif
} else {
info = none;
}
images += ImagePackImage{
k,
#ifdef QUOTIENT_07
fromJson<QUrl>(json["images"][k]["url"].toString()),
#else
QUrl(),
#endif
fromJson<Omittable<QString>>(json["images"][k]["body"]),
info,
fromJson<Omittable<QStringList>>(json["images"][k]["usage"]),

View File

@@ -4,8 +4,8 @@
#pragma once
#include <QVector>
#include <Quotient/events/eventcontent.h>
#include <Quotient/events/stateevent.h>
#include <events/eventcontent.h>
#include <events/stateevent.h>
namespace Quotient
{
@@ -83,11 +83,23 @@ public:
*
* @sa Quotient::StateEvent, ImagePackEventContent
*/
#ifdef QUOTIENT_07
class ImagePackEvent : public KeyedStateEventBase<ImagePackEvent, ImagePackEventContent>
#else
class ImagePackEvent : public StateEvent<ImagePackEventContent>
#endif
{
public:
#ifdef QUOTIENT_07
QUO_EVENT(ImagePackEvent, "im.ponies.room_emotes")
using KeyedStateEventBase::KeyedStateEventBase;
#else
DEFINE_EVENT_TYPEID("im.ponies.room_emotes", ImagePackEvent)
explicit ImagePackEvent(const QJsonObject &obj)
: StateEvent(typeId(), obj)
{
}
#endif
};
REGISTER_EVENT_TYPE(ImagePackEvent)

View File

@@ -3,7 +3,7 @@
#pragma once
#include <Quotient/events/stateevent.h>
#include <events/stateevent.h>
namespace Quotient
{
@@ -14,13 +14,25 @@ namespace Quotient
*
* @sa Quotient::StateEvent
*/
#ifdef QUOTIENT_07
class JoinRulesEvent : public StateEvent
#else
class JoinRulesEvent : public StateEventBase
#endif
{
public:
#ifdef QUOTIENT_07
QUO_EVENT(JoinRulesEvent, "m.room.join_rules")
#else
DEFINE_EVENT_TYPEID("m.room.join_rules", JoinRulesEvent)
#endif
explicit JoinRulesEvent(const QJsonObject &obj)
#ifdef QUOTIENT_07
: StateEvent(obj)
#else
: StateEventBase(typeId(), obj)
#endif
{
}

View File

@@ -3,7 +3,8 @@
#pragma once
#include <Quotient/events/roomevent.h>
#include <events/eventcontent.h>
#include <events/roomevent.h>
namespace Quotient
{

View File

@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 2020 Carl Schwan <carlschwan@kde.org>
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "stickerevent.h"
using namespace Quotient;
StickerEvent::StickerEvent(const QJsonObject &obj)
#ifdef QUOTIENT_07
: RoomEvent(obj)
#else
: RoomEvent(typeId(), obj)
#endif
, m_imageContent(EventContent::ImageContent(obj["content"_ls].toObject()))
{
}
QString StickerEvent::body() const
{
return content<QString>("body"_ls);
}
const EventContent::ImageContent &StickerEvent::image() const
{
return m_imageContent;
}
QUrl StickerEvent::url() const
{
#ifdef QUOTIENT_07
return m_imageContent.url();
#else
return m_imageContent.url;
#endif
}

55
src/events/stickerevent.h Normal file
View File

@@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: 2020 Carl Schwan <carlschwan@kde.org>
// SPDX-License-Identifier: LGPL-2.1-or-later
#pragma once
#include <events/eventcontent.h>
#include <events/roomevent.h>
namespace Quotient
{
/**
* @class StickerEvent
*
* Class to define a sticker event.
*
* Sticker messages are specialised image messages that are displayed without
* controls (e.g. no "download" link, or light-box view on click, as would be
* displayed for for m.image events).
*
* @sa Quotient::RoomEvent
*/
class StickerEvent : public RoomEvent
{
public:
#ifdef QUOTIENT_07
QUO_EVENT(StickerEvent, "m.sticker")
#else
DEFINE_EVENT_TYPEID("m.sticker", StickerEvent)
#endif
explicit StickerEvent(const QJsonObject &obj);
/**
* @brief A textual representation or associated description of the sticker image.
*
* This could be the alt text of the original image, or a message to accompany
* and further describe the sticker.
*/
QString body() const;
/**
* @brief Metadata about the image referred to in url including a thumbnail representation.
*/
const EventContent::ImageContent &image() const;
/**
* @brief The URL to the sticker image. This must be a valid mxc:// URI.
*/
QUrl url() const;
private:
EventContent::ImageContent m_imageContent;
};
REGISTER_EVENT_TYPE(StickerEvent)
}

View File

@@ -14,7 +14,7 @@ FileTransferPseudoJob::FileTransferPseudoJob(Operation operation, const QString
{
}
void FileTransferPseudoJob::fileTransferProgress(const QString &id, qint64 progress, qint64 total)
void FileTransferPseudoJob::fileTransferProgress(QString id, qint64 progress, qint64 total)
{
if (id != m_eventId) {
return;
@@ -23,7 +23,7 @@ void FileTransferPseudoJob::fileTransferProgress(const QString &id, qint64 progr
setTotalAmount(Unit::Bytes, total);
}
void FileTransferPseudoJob::fileTransferCompleted(const QString &id, const QUrl &localFile)
void FileTransferPseudoJob::fileTransferCompleted(QString id, QUrl localFile)
{
Q_UNUSED(localFile);
if (id != m_eventId) {
@@ -32,7 +32,7 @@ void FileTransferPseudoJob::fileTransferCompleted(const QString &id, const QUrl
emitResult();
}
void FileTransferPseudoJob::fileTransferFailed(const QString &id, const QString &errorMessage)
void FileTransferPseudoJob::fileTransferFailed(QString id, QString errorMessage)
{
if (id != m_eventId) {
return;

View File

@@ -20,23 +20,23 @@ public:
Download,
Upload,
};
Q_ENUM(Operation)
Q_ENUM(Operation);
FileTransferPseudoJob(Operation operation, const QString &srcDest, const QString &path);
/**
* @brief Set the current number of bytes transferred.
*/
void fileTransferProgress(const QString &id, qint64 progress, qint64 total);
void fileTransferProgress(QString id, qint64 progress, qint64 total);
/**
* @brief Set the file transfer as complete.
*/
void fileTransferCompleted(const QString &id, const QUrl &localFile);
void fileTransferCompleted(QString id, QUrl localFile);
/**
* @brief Set the file transfer as failed.
*/
void fileTransferFailed(const QString &id, const QString &errorMessage = {});
void fileTransferFailed(QString id, QString errorMessage = {});
/**
* @brief Start the file transfer.

View File

@@ -112,5 +112,3 @@ QStringList FileTypeSingleton::supportedAnimatedImageFormats() const
Q_D(const FileTypeSingleton);
return d->supportedAnimatedImageFormats;
}
#include "moc_filetypesingleton.cpp"

View File

@@ -5,7 +5,6 @@
#pragma once
#include <QFileInfo>
#include <QMimeDatabase>
#include <QObject>
#include <qqml.h>

View File

@@ -3,16 +3,14 @@
#include "linkpreviewer.h"
#include "controller.h"
#include <Quotient/connection.h>
#include <Quotient/csapi/content-repo.h>
#include <connection.h>
#include <csapi/content-repo.h>
#include "neochatroom.h"
using namespace Quotient;
LinkPreviewer::LinkPreviewer(QObject *parent, NeoChatRoom *room, const QUrl &url)
LinkPreviewer::LinkPreviewer(QObject *parent, NeoChatRoom *room, QUrl url)
: QObject(parent)
, m_currentRoom(room)
, m_loaded(false)
@@ -71,7 +69,14 @@ void LinkPreviewer::loadUrlPreview()
auto imageUrl = QUrl(json["og:image"].toString());
if (imageUrl.isValid() && imageUrl.scheme() == QStringLiteral("mxc")) {
#ifdef QUOTIENT_07
m_imageSource = conn->makeMediaUrl(imageUrl);
#else
QUrlQuery q(imageUrl.query());
q.addQueryItem(QStringLiteral("user_id"), conn->userId());
imageUrl.setQuery(q);
m_imageSource = imageUrl;
#endif
} else {
m_imageSource = QUrl();
}
@@ -84,5 +89,3 @@ void LinkPreviewer::loadUrlPreview()
});
}
}
#include "moc_linkpreviewer.cpp"

View File

@@ -45,7 +45,7 @@ class LinkPreviewer : public QObject
Q_PROPERTY(QUrl imageSource READ imageSource NOTIFY imageSourceChanged)
public:
explicit LinkPreviewer(QObject *parent = nullptr, NeoChatRoom *room = nullptr, const QUrl &url = {});
explicit LinkPreviewer(QObject *parent = nullptr, NeoChatRoom *room = nullptr, QUrl url = {});
[[nodiscard]] QUrl url() const;
void setUrl(QUrl);

View File

@@ -1,46 +0,0 @@
// SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "locationhelper.h"
#include <cmath>
QRectF LocationHelper::unite(const QRectF &r1, const QRectF &r2)
{
// this looks weird but is actually intentional as we need to handle point-like "rects" as well
if ((!r1.isEmpty() || r1.isNull()) && (!r2.isEmpty() || r2.isNull())) {
return r1 | r2;
}
return (!r1.isEmpty() || r1.isNull()) ? r1 : r2;
}
QPointF LocationHelper::center(const QRectF &r)
{
return r.center();
}
constexpr inline double degToRad(double deg)
{
return deg / 180.0 * M_PI;
}
static QPointF mercatorProject(double lat, double lon, double zoom)
{
const auto x = (256.0 / (2.0 * M_PI)) * std::pow(2.0, zoom) * (degToRad(lon) + M_PI);
const auto y = (256.0 / (2.0 * M_PI)) * std::pow(2.0, zoom) * (M_PI - std::log(std::tan(M_PI / 4.0 + degToRad(lat) / 2.0)));
return QPointF(x, y);
}
float LocationHelper::zoomToFit(const QRectF &r, float mapWidth, float mapHeight)
{
const auto p1 = mercatorProject(r.bottomLeft().y(), r.bottomLeft().x(), 1.0);
const auto p2 = mercatorProject(r.topRight().y(), r.topRight().x(), 1.0);
const auto zx = std::log2((mapWidth / (p2.x() - p1.x())));
const auto zy = std::log2((mapHeight / (p2.y() - p1.y())));
const auto z = std::min(zx, zy);
return std::clamp(z, 5.0, 18.0);
}
#include "moc_locationhelper.cpp"

View File

@@ -1,23 +0,0 @@
// SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include "linkpreviewer.h"
#include <QMetaType>
#include <QRectF>
/** Location related helper functions for QML. */
class LocationHelper
{
Q_GADGET
public:
/** Unite two rectanlges. */
Q_INVOKABLE static QRectF unite(const QRectF &r1, const QRectF &r2);
/** Returns the center of @p r. */
Q_INVOKABLE static QPointF center(const QRectF &r);
/** Returns the highest zoom level to fit @r into a map of size @p mapWidth x @p mapHeight. */
Q_INVOKABLE static float zoomToFit(const QRectF &r, float mapWidth, float mapHeight);
};
Q_DECLARE_METATYPE(LocationHelper)

View File

@@ -3,9 +3,14 @@
#include "login.h"
#include <Quotient/accountregistry.h>
#include <Quotient/connection.h>
#include <Quotient/qt_connection_util.h>
#ifdef QUOTIENT_07
#include <accountregistry.h>
#else
#include "neochataccountregistry.h"
#endif
#include <connection.h>
#include <qt_connection_util.h>
#include "controller.h"
@@ -42,7 +47,11 @@ void Login::init()
return;
}
m_isLoggedIn = Controller::instance().accounts().isLoggedIn(m_matrixId);
#ifdef QUOTIENT_07
m_isLoggedIn = Accounts.isLoggedIn(m_matrixId);
#else
m_isLoggedIn = AccountRegistry::instance().isLoggedIn(m_matrixId);
#endif
Q_EMIT isLoggedInChanged();
if (m_isLoggedIn) {
return;
@@ -96,7 +105,7 @@ void Login::init()
Q_EMIT Controller::instance().globalErrorOccured(i18n("Network Error"), std::move(error));
});
connectSingleShot(m_connection, &Connection::syncDone, this, []() {
connectSingleShot(m_connection, &Connection::syncDone, this, [this]() {
Q_EMIT Controller::instance().initiated();
});
}
@@ -198,5 +207,3 @@ bool Login::isLoggedIn() const
{
return m_isLoggedIn;
}
#include "moc_login.cpp"

View File

@@ -112,7 +112,7 @@ Q_SIGNALS:
void loginFlowsChanged();
void ssoUrlChanged();
void connected();
void errorOccured(const QString &message);
void errorOccured(QString message);
void testingChanged();
void isLoggingInChanged();
void isLoggedInChanged();

View File

@@ -4,7 +4,6 @@
#include <QCommandLineParser>
#include <QIcon>
#include <QNetworkProxyFactory>
#include <QObject>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQmlNetworkAccessManagerFactory>
@@ -29,11 +28,15 @@
#include "neochat-version.h"
#include <Quotient/keyverificationsession.h>
#include <Quotient/accountregistry.h>
#include <Quotient/networkaccessmanager.h>
#include <Quotient/room.h>
#include <Quotient/util.h>
#ifdef QUOTIENT_07
#include <accountregistry.h>
#else
#include "neochataccountregistry.h"
#endif
#include <networkaccessmanager.h>
#include <room.h>
#include <util.h>
#include "actionshandler.h"
#include "blurhashimageprovider.h"
@@ -43,7 +46,6 @@
#include "delegatesizehelper.h"
#include "filetypesingleton.h"
#include "linkpreviewer.h"
#include "locationhelper.h"
#include "logger.h"
#include "login.h"
#include "matriximageprovider.h"
@@ -51,25 +53,19 @@
#include "models/collapsestateproxymodel.h"
#include "models/customemojimodel.h"
#include "models/devicesmodel.h"
#include "models/devicesproxymodel.h"
#include "models/emojimodel.h"
#include "models/emoticonfiltermodel.h"
#include "models/imagepacksmodel.h"
#include "models/livelocationsmodel.h"
#include "models/locationsmodel.h"
#include "models/mediamessagefiltermodel.h"
#include "models/keywordnotificationrulemodel.h"
#include "models/messageeventmodel.h"
#include "models/messagefiltermodel.h"
#include "models/publicroomlistmodel.h"
#include "models/pushrulemodel.h"
#include "models/reactionmodel.h"
#include "models/roomlistmodel.h"
#include "models/searchmodel.h"
#include "models/serverlistmodel.h"
#include "models/sortfilterroomlistmodel.h"
#include "models/sortfilterspacelistmodel.h"
#include "models/statefiltermodel.h"
#include "models/stickermodel.h"
#include "models/userdirectorylistmodel.h"
#include "models/userfiltermodel.h"
#include "models/userlistmodel.h"
@@ -78,11 +74,19 @@
#include "neochatroom.h"
#include "neochatuser.h"
#include "notificationsmanager.h"
#ifdef QUOTIENT_07
#include "pollhandler.h"
#endif
#include "models/statefiltermodel.h"
#include "models/stickermodel.h"
#include "roommanager.h"
#include "spacehierarchycache.h"
#include "urlhelper.h"
#include "windowcontroller.h"
#ifdef QUOTIENT_07
#include <keyverificationsession.h>
#endif
#include <room.h>
#ifdef HAVE_COLORSCHEME
#include "colorschemer.h"
@@ -91,6 +95,14 @@
#include "models/statemodel.h"
#include "neochatuser.h"
#ifdef GSTREAMER_AVAILABLE
#include "call/audiosources.h"
#include "call/callmanager.h"
#include "call/callparticipant.h"
#include "call/videosources.h"
#include "models/callparticipantsmodel.h"
#endif
#ifdef HAVE_RUNNER
#include "runner.h"
#include <QDBusConnection>
@@ -123,9 +135,7 @@ Q_DECL_EXPORT
#endif
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QNetworkProxyFactory::setUseSystemConfiguration(true);
@@ -173,22 +183,38 @@ int main(int argc, char *argv[])
about.addComponent(QStringLiteral("libQuotient"),
i18n("A Qt5 library to write cross-platform clients for Matrix"),
#ifdef QUOTIENT_07
i18nc("<version number> (built against <possibly different version number>)",
"%1 (built against %2)",
Quotient::versionString(),
QStringLiteral(Quotient_VERSION_STRING)),
#else
QStringLiteral(QUOTIENT_VERSION),
#endif
QStringLiteral("https://github.com/quotient-im/libquotient"),
KAboutLicense::LGPL_V2_1);
#ifdef GSTREAMER_AVAILABLE
guint major, minor, micro, nano;
gst_version(&major, &minor, &micro, &nano);
about.addComponent(QStringLiteral("GStreamer"),
i18nc("Description of GStreamer", "Open Source Multimedia Framework"),
i18nc("<version number> (built against <possibly different version number>)",
"%1.%2.%3.%4 (built against %5.%6.%7.%8)",
major,
minor,
micro,
nano,
GST_VERSION_MAJOR,
GST_VERSION_MINOR,
GST_VERSION_MICRO,
GST_VERSION_NANO));
#endif
KAboutData::setApplicationData(about);
QGuiApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("org.kde.neochat")));
initLogging();
#if Quotient_VERSION_MINOR == 8
Connection::setEncryptionDefault(true);
#endif
#ifdef NEOCHAT_FLATPAK
// Copy over the included FontConfig configuration to the
// app's config dir:
@@ -219,7 +245,11 @@ int main(int argc, char *argv[])
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "UrlHelper", &urlHelper);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", &EmojiModel::instance());
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Controller::instance().accounts());
#ifdef QUOTIENT_07
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::Accounts);
#else
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::AccountRegistry::instance());
#endif
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "SpaceHierarchyCache", &SpaceHierarchyCache::instance());
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CustomEmojiModel", &CustomEmojiModel::instance());
qmlRegisterType<ActionsHandler>("org.kde.neochat", 1, 0, "ActionsHandler");
@@ -230,7 +260,6 @@ int main(int argc, char *argv[])
qmlRegisterType<MessageEventModel>("org.kde.neochat", 1, 0, "MessageEventModel");
qmlRegisterType<ReactionModel>("org.kde.neochat", 1, 0, "ReactionModel");
qmlRegisterType<CollapseStateProxyModel>("org.kde.neochat", 1, 0, "CollapseStateProxyModel");
qmlRegisterType<MediaMessageFilterModel>("org.kde.neochat", 1, 0, "MediaMessageFilterModel");
qmlRegisterType<MessageFilterModel>("org.kde.neochat", 1, 0, "MessageFilterModel");
qmlRegisterType<UserFilterModel>("org.kde.neochat", 1, 0, "UserFilterModel");
qmlRegisterType<PublicRoomListModel>("org.kde.neochat", 1, 0, "PublicRoomListModel");
@@ -239,30 +268,31 @@ int main(int argc, char *argv[])
qmlRegisterType<SortFilterRoomListModel>("org.kde.neochat", 1, 0, "SortFilterRoomListModel");
qmlRegisterType<SortFilterSpaceListModel>("org.kde.neochat", 1, 0, "SortFilterSpaceListModel");
qmlRegisterType<DevicesModel>("org.kde.neochat", 1, 0, "DevicesModel");
qmlRegisterType<DevicesProxyModel>("org.kde.neochat", 1, 0, "DevicesProxyModel");
qmlRegisterType<LinkPreviewer>("org.kde.neochat", 1, 0, "LinkPreviewer");
qmlRegisterType<CompletionModel>("org.kde.neochat", 1, 0, "CompletionModel");
qmlRegisterType<StateModel>("org.kde.neochat", 1, 0, "StateModel");
qmlRegisterType<StateFilterModel>("org.kde.neochat", 1, 0, "StateFilterModel");
qmlRegisterType<SearchModel>("org.kde.neochat", 1, 0, "SearchModel");
qmlRegisterType<LiveLocationsModel>("org.kde.neochat", 1, 0, "LiveLocationsModel");
qmlRegisterType<LocationsModel>("org.kde.neochat", 1, 0, "LocationsModel");
#ifdef QUOTIENT_07
qmlRegisterType<PollHandler>("org.kde.neochat", 1, 0, "PollHandler");
qmlRegisterType<PushRuleModel>("org.kde.neochat", 1, 0, "PushRuleModel");
#endif
qmlRegisterType<KeywordNotificationRuleModel>("org.kde.neochat", 1, 0, "KeywordNotificationRuleModel");
qmlRegisterType<StickerModel>("org.kde.neochat", 1, 0, "StickerModel");
qmlRegisterType<ImagePacksModel>("org.kde.neochat", 1, 0, "ImagePacksModel");
qmlRegisterType<AccountEmoticonModel>("org.kde.neochat", 1, 0, "AccountEmoticonModel");
qmlRegisterType<EmoticonFilterModel>("org.kde.neochat", 1, 0, "EmoticonFilterModel");
qmlRegisterType<DelegateSizeHelper>("org.kde.neochat", 1, 0, "DelegateSizeHelper");
qmlRegisterUncreatableType<RoomMessageEvent>("org.kde.neochat", 1, 0, "RoomMessageEvent", "ENUM");
qmlRegisterUncreatableType<PushNotificationKind>("org.kde.neochat", 1, 0, "PushNotificationKind", "ENUM");
qmlRegisterUncreatableType<PushNotificationSection>("org.kde.neochat", 1, 0, "PushNotificationSection", "ENUM");
qmlRegisterUncreatableType<PushNotificationState>("org.kde.neochat", 1, 0, "PushNotificationState", "ENUM");
qmlRegisterUncreatableType<PushNotificationAction>("org.kde.neochat", 1, 0, "PushNotificationAction", "ENUM");
qmlRegisterUncreatableType<NeoChatRoomType>("org.kde.neochat", 1, 0, "NeoChatRoomType", "ENUM");
qmlRegisterUncreatableType<NeoChatUser>("org.kde.neochat", 1, 0, "NeoChatUser", {});
qmlRegisterUncreatableType<NeoChatRoom>("org.kde.neochat", 1, 0, "NeoChatRoom", {});
#ifdef GSTREAMER_AVAILABLE
qmlRegisterUncreatableType<CallParticipantsModel>("org.kde.neochat", 1, 0, "CallParticipantsModel", "Get through CallManager");
qmlRegisterUncreatableType<CallParticipant>("org.kde.neochat", 1, 0, "CallParticipant", "Get through model");
#endif
qRegisterMetaType<User *>("User*");
qRegisterMetaType<User *>("const User*");
qRegisterMetaType<User *>("const Quotient::User*");
@@ -273,18 +303,24 @@ int main(int argc, char *argv[])
qRegisterMetaType<NeoChatUser *>("NeoChatUser*");
qRegisterMetaType<GetRoomEventsJob *>("GetRoomEventsJob*");
qRegisterMetaType<QMimeType>("QMimeType");
#ifdef QUOTIENT_07
#ifdef Quotient_E2EE_ENABLED
qRegisterMetaType<KeyVerificationSession *>("KeyVerificationSession*");
qmlRegisterUncreatableType<KeyVerificationSession>("org.kde.neochat", 1, 0, "KeyVerificationSession", {});
qRegisterMetaType<QVector<EmojiEntry>>("QVector<EmojiEntry>");
#endif
#endif
#ifdef GSTREAMER_AVAILABLE
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AudioSources", &AudioSources::instance());
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "VideoSources", &VideoSources::instance());
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CallManager", &CallManager::instance());
qmlRegisterUncreatableType<CallSession>("org.kde.neochat", 1, 0, "CallSession", "ENUM");
#endif
qmlRegisterSingletonType("org.kde.neochat", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue {
return engine->toScriptValue(KAboutData::applicationData());
});
qmlRegisterSingletonType(QUrl("qrc:/OsmLocationPlugin.qml"), "org.kde.neochat", 1, 0, "OsmLocationPlugin");
qmlRegisterSingletonType("org.kde.neochat", 1, 0, "LocationHelper", [](QQmlEngine *engine, QJSEngine *) -> QJSValue {
return engine->toScriptValue(LocationHelper());
});
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qRegisterMetaTypeStreamOperators<Emoji>();
@@ -324,18 +360,11 @@ int main(int argc, char *argv[])
QCommandLineParser parser;
parser.setApplicationDescription(i18n("Client for the matrix communication protocol"));
parser.addPositionalArgument(QStringLiteral("urls"), i18n("Supports matrix: url scheme"));
parser.addOption(QCommandLineOption("ignore-ssl-errors", i18n("Ignore all SSL Errors, e.g., unsigned certificates.")));
about.setupCommandLine(&parser);
parser.process(app);
about.processCommandLine(&parser);
if (parser.isSet("ignore-ssl-errors")) {
QObject::connect(NetworkAccessManager::instance(), &QNetworkAccessManager::sslErrors, NetworkAccessManager::instance(), [](QNetworkReply *reply) {
reply->ignoreSslErrors();
});
}
engine.addImageProvider(QLatin1String("mxc"), new MatrixImageProvider);
engine.addImageProvider(QLatin1String("blurhash"), new BlurhashImageProvider);

View File

@@ -13,7 +13,7 @@
#include <KLocalizedString>
#include "controller.h"
#include <Quotient/connection.h>
#include <connection.h>
using namespace Quotient;
@@ -114,5 +114,3 @@ QQuickImageResponse *MatrixImageProvider::requestImageResponse(const QString &id
{
return new ThumbnailResponse(id, requestedSize);
}
#include "moc_matriximageprovider.cpp"

View File

@@ -6,7 +6,7 @@
#include <QQuickAsyncImageProvider>
#include <Quotient/jobs/mediathumbnailjob.h>
#include <jobs/mediathumbnailjob.h>
#include <QReadWriteLock>
@@ -26,7 +26,7 @@ class ThumbnailResponse : public QQuickImageResponse
{
Q_OBJECT
public:
explicit ThumbnailResponse(QString mediaId, QSize requestedSize);
ThumbnailResponse(QString mediaId, QSize requestedSize);
~ThumbnailResponse() override = default;
private Q_SLOTS:

Some files were not shown because too many files have changed in this diff Show More