Move remaining code to app module

There's still some stuff that could potentially go elsewhere but I think it's enough for now.
This commit is contained in:
James Graham
2025-04-18 09:26:17 +00:00
parent 0708f022bc
commit b6791485c4
124 changed files with 406 additions and 403 deletions

372
src/app/CMakeLists.txt Normal file
View File

@@ -0,0 +1,372 @@
# SPDX-FileCopyrightText: 2020-2021 Carl Schwan <carl@carlschwan.eu>
# SPDX-FileCopyrightText: 2020-2021 Nicolas Fella <nicolas.fella@gmx.de>
# SPDX-FileCopyrightText: 2020-2021 Tobias Fella <tobias.fella@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
add_library(neochat STATIC
controller.cpp
controller.h
roommanager.cpp
roommanager.h
models/userfiltermodel.cpp
models/userfiltermodel.h
models/userdirectorylistmodel.cpp
models/userdirectorylistmodel.h
notificationsmanager.cpp
notificationsmanager.h
blurhash.cpp
blurhash.h
blurhashimageprovider.cpp
blurhashimageprovider.h
windowcontroller.cpp
windowcontroller.h
models/serverlistmodel.cpp
models/serverlistmodel.h
logger.cpp
logger.h
models/notificationsmodel.cpp
models/notificationsmodel.h
proxycontroller.cpp
proxycontroller.h
mediamanager.cpp
mediamanager.h
sharehandler.cpp
sharehandler.h
foreigntypes.h
identityserverhelper.cpp
identityserverhelper.h
models/commonroomsmodel.cpp
models/commonroomsmodel.h
)
set_source_files_properties(qml/TextToSpeechWrapper.qml PROPERTIES
QT_QML_SINGLETON_TYPE TRUE
)
set_source_files_properties(qml/OsmLocationPlugin.qml PROPERTIES
QT_QML_SINGLETON_TYPE TRUE
)
if(ANDROID OR WIN32)
set_source_files_properties(qml/ShareActionStub.qml PROPERTIES
QT_QML_SOURCE_TYPENAME ShareAction
)
endif()
ecm_add_qml_module(neochat URI org.kde.neochat GENERATE_PLUGIN_SOURCE
OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/src/org/kde/neochat
QML_FILES
qml/Main.qml
qml/AccountMenu.qml
qml/CollapsedRoomDelegate.qml
qml/RoomPage.qml
qml/ExploreRoomsPage.qml
qml/ManualRoomDialog.qml
qml/ExplorerDelegate.qml
qml/InviteUserPage.qml
qml/ImageEditorPage.qml
qml/NeochatMaximizeComponent.qml
qml/TypingPane.qml
qml/QuickSwitcher.qml
qml/HoverActions.qml
qml/AttachmentPane.qml
qml/QuickFormatBar.qml
qml/UserDetailDialog.qml
qml/CreateRoomDialog.qml
qml/OpenFileDialog.qml
qml/KeyVerificationDialog.qml
qml/ConfirmLogoutDialog.qml
qml/VerificationMessage.qml
qml/EmojiItem.qml
qml/EmojiRow.qml
qml/EmojiSas.qml
qml/VerificationCanceled.qml
qml/MessageSourceSheet.qml
qml/RoomSearchPage.qml
qml/RoomPinnedMessagesPage.qml
qml/LocationChooser.qml
qml/InvitationView.qml
qml/AvatarTabButton.qml
qml/OsmLocationPlugin.qml
qml/TextToSpeechWrapper.qml
qml/FullScreenMap.qml
qml/LocationsPage.qml
qml/LocationMapItem.qml
qml/RoomDrawer.qml
qml/RoomDrawerPage.qml
qml/DirectChatDrawerHeader.qml
qml/GroupChatDrawerHeader.qml
qml/RoomInformation.qml
qml/RoomMedia.qml
qml/ChooseRoomDialog.qml
qml/RemoveChildDialog.qml
qml/QrCodeMaximizeComponent.qml
qml/NotificationsView.qml
qml/SearchPage.qml
qml/ServerComboBox.qml
qml/UserSearchPage.qml
qml/ManualUserDialog.qml
qml/RecommendedSpaceDialog.qml
qml/ShareDialog.qml
qml/UnlockSSSSDialog.qml
qml/QrScannerPage.qml
qml/JoinRoomDialog.qml
qml/ConfirmUrlDialog.qml
qml/AccountSwitchDialog.qml
qml/ConfirmLeaveDialog.qml
qml/CodeMaximizeComponent.qml
qml/EditStateDialog.qml
qml/ConsentDialog.qml
qml/AskDirectChatConfirmation.qml
qml/HoverLinkIndicator.qml
qml/AvatarNotification.qml
qml/ReasonDialog.qml
qml/NewPollDialog.qml
DEPENDENCIES
QtCore
QtQuick
IMPORTS
org.kde.neochat.libneochat
org.kde.neochat.rooms
org.kde.neochat.timeline
org.kde.neochat.spaces
org.kde.neochat.settings
org.kde.neochat.devtools
org.kde.neochat.login
org.kde.neochat.chatbar
)
if(NOT ANDROID AND NOT WIN32)
qt_target_qml_sources(neochat QML_FILES
qml/ShareAction.qml
qml/GlobalMenu.qml
qml/EditMenu.qml
)
else()
qt_target_qml_sources(neochat QML_FILES qml/ShareActionStub.qml)
endif()
if(WIN32)
set_target_properties(neochat PROPERTIES OUTPUT_NAME "neochatlib")
endif()
add_executable(neochat-app
main.cpp
)
if(TARGET Qt::WebView)
target_link_libraries(neochat-app PUBLIC Qt::WebView)
target_compile_definitions(neochat-app PUBLIC -DHAVE_WEBVIEW)
endif()
target_include_directories(neochat-app PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(neochat-app PRIVATE
neochat
)
ecm_add_app_icon(NEOCHAT_ICON ICONS ${CMAKE_SOURCE_DIR}/128-logo.png)
target_sources(neochat-app PRIVATE ${NEOCHAT_ICON})
if(NOT ANDROID)
if (NOT WIN32 AND NOT APPLE)
target_sources(neochat PRIVATE trayicon_sni.cpp trayicon_sni.h)
target_link_libraries(neochat PRIVATE KF6::StatusNotifierItem)
else()
target_sources(neochat PRIVATE trayicon.cpp trayicon.h)
endif()
target_link_libraries(neochat PUBLIC KF6::WindowSystem)
target_compile_definitions(neochat PUBLIC -DHAVE_WINDOWSYSTEM)
endif()
if (NOT ANDROID AND NOT WIN32 AND NOT APPLE AND NOT HAIKU)
target_compile_definitions(neochat PUBLIC -DHAVE_RUNNER)
target_compile_definitions(neochat PUBLIC -DHAVE_X11=1)
target_sources(neochat PRIVATE runner.cpp)
if (TARGET KUnifiedPush)
target_sources(neochat PRIVATE fakerunner.cpp)
endif()
else()
target_compile_definitions(neochat PUBLIC -DHAVE_X11=0)
endif()
target_include_directories(neochat PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/models)
target_link_libraries(neochat PRIVATE Loginplugin Roomsplugin Timelineplugin Spacesplugin Chatbarplugin Settingsplugin Devtoolsplugin)
target_link_libraries(neochat PUBLIC
LibNeoChat
Timeline
Settings
Qt::Core
Qt::Quick
Qt::Qml
Qt::Gui
Qt::Multimedia
Qt::Network
Qt::QuickControls2
KF6::I18n
KF6::Kirigami
KF6::Notifications
KF6::ConfigCore
KF6::ConfigGui
KF6::CoreAddons
KF6::SonnetCore
KF6::IconThemes
KF6::ItemModels
QuotientQt6
Login
Rooms
Spaces
)
if (TARGET KF6::Crash)
target_link_libraries(neochat PUBLIC KF6::Crash)
endif()
kconfig_target_kcfg_file(neochat FILE neochatconfig.kcfg CLASS_NAME NeoChatConfig MUTATORS GENERATE_PROPERTIES DEFAULT_VALUE_GETTERS PARENT_IN_CONSTRUCTOR SINGLETON GENERATE_MOC QML_REGISTRATION)
if(NEOCHAT_FLATPAK)
target_compile_definitions(neochat PUBLIC NEOCHAT_FLATPAK)
endif()
if(ANDROID)
target_sources(neochat PRIVATE notifyrc.qrc)
target_link_libraries(neochat PRIVATE Qt::Svg OpenSSL::SSL)
if(SQLite3_FOUND)
target_link_libraries(neochat-app PRIVATE SQLite::SQLite3)
endif()
target_sources(neochat-app PRIVATE notifyrc.qrc)
target_link_libraries(neochat PUBLIC Qt::Svg OpenSSL::SSL)
kirigami_package_breeze_icons(ICONS
"arrow-down-symbolic"
"arrow-up-symbolic"
"arrow-up-double-symbolic"
"arrow-left-symbolic"
"arrow-right-symbolic"
"checkmark"
"help-about"
"im-user"
"im-invisible-user"
"im-kick-user"
"mail-attachment"
"dialog-cancel"
"preferences-desktop-emoticons"
"preferences-security"
"document-open"
"document-save"
"document-send"
"dialog-close"
"edit-delete-remove"
"code-context"
"document-edit"
"list-user-add"
"list-add-user"
"user-others"
"media-playback-pause"
"media-playback-start"
"media-playback-stop"
"go-previous"
"go-up"
"go-down"
"list-add"
"irc-join-channel"
"settings-configure"
"configure"
"rating"
"rating-unrated"
"search"
"mail-replied-symbolic"
"edit-clear"
"edit-copy"
"gtk-quit"
"compass"
"computer"
"network-connect"
"list-remove-user"
"org.kde.neochat"
"org.kde.neochat.tray"
"preferences-system-users"
"preferences-desktop-theme-global"
"notifications"
"notifications-disabled"
"audio-volume-high"
"audio-volume-muted"
"draw-highlight"
"zoom-in"
"zoom-out"
"image-rotate-left-symbolic"
"image-rotate-right-symbolic"
"channel-secure-symbolic"
"download"
"smiley"
"tools-check-spelling"
"username-copy"
"system-switch-user"
"bookmark-new"
"bookmark-remove"
"favorite"
"window-new"
"globe"
"visibility"
"home"
"preferences-desktop-notification"
"computer-symbolic"
"gps"
"system-users-symbolic"
"map-flat"
"documentinfo"
"view-list-details"
"go-previous"
"mail-forward-symbolic"
"dialog-warning-symbolic"
"object-rotate-left"
"object-rotate-right"
"add-subtitle"
"security-high"
"security-low"
"security-low-symbolic"
"kde"
"list-remove-symbolic"
"edit-delete"
"user-home-symbolic"
"pin-symbolic"
"kt-restore-defaults-symbolic"
"user-symbolic"
${KIRIGAMI_ADDONS_ICONS}
)
ecm_add_android_apk(neochat-app ANDROID_DIR ${CMAKE_SOURCE_DIR}/android)
else()
target_link_libraries(neochat PUBLIC Qt::Widgets KF6::KIOWidgets)
install(FILES neochat.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFYRCDIR})
endif()
if(NOT ANDROID)
set_target_properties(neochat-app PROPERTIES OUTPUT_NAME "neochat")
endif()
if(TARGET KF6::DBusAddons AND NOT WIN32)
target_link_libraries(neochat PUBLIC KF6::DBusAddons)
target_compile_definitions(neochat PUBLIC -DHAVE_KDBUSADDONS)
endif()
if (TARGET KF6::KIOWidgets)
target_compile_definitions(neochat PUBLIC -DHAVE_KIO)
endif()
if (TARGET KUnifiedPush)
target_compile_definitions(neochat PUBLIC -DHAVE_KUNIFIEDPUSH)
target_link_libraries(neochat PUBLIC KUnifiedPush)
if (NOT ANDROID)
configure_file(org.kde.neochat.service.in ${CMAKE_CURRENT_BINARY_DIR}/org.kde.neochat.service)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.neochat.service DESTINATION ${KDE_INSTALL_DBUSSERVICEDIR})
endif()
endif()
install(TARGETS neochat-app ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
if (NOT ANDROID AND NOT WIN32 AND NOT APPLE)
install(FILES plasma-runner-neochat.desktop DESTINATION ${KDE_INSTALL_DATAROOTDIR}/krunner/dbusplugins)
endif()

198
src/app/blurhash.cpp Normal file
View File

@@ -0,0 +1,198 @@
// SPDX-FileCopyrightText: 2018 Wolt Enterprises
// SPDX-License-Identifier: MIT
#include "blurhash.h"
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
namespace
{
const char chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~";
struct Color {
float r = 0;
float g = 0;
float b = 0;
};
inline int linearTosRGB(float value)
{
float v = fmaxf(0, fminf(1, value));
if (v <= 0.0031308)
return v * 12.92 * 255 + 0.5;
else
return (1.055 * powf(v, 1 / 2.4) - 0.055) * 255 + 0.5;
}
inline float sRGBToLinear(int value)
{
float v = (float)value / 255;
if (v <= 0.04045)
return v / 12.92;
else
return powf((v + 0.055) / 1.055, 2.4);
}
inline float signPow(float value, float exp)
{
return copysignf(powf(fabsf(value), exp), value);
}
inline uint8_t clampToUByte(int *src)
{
if (*src >= 0 && *src <= 255) {
return *src;
}
return (*src < 0) ? 0 : 255;
}
inline uint8_t *createByteArray(int size)
{
return (uint8_t *)malloc(size * sizeof(uint8_t));
}
int decodeToInt(const char *string, int start, int end)
{
int value = 0;
for (int iter1 = start; iter1 < end; iter1++) {
int index = -1;
for (int iter2 = 0; iter2 < 83; iter2++) {
if (chars[iter2] == string[iter1]) {
index = iter2;
break;
}
}
if (index == -1) {
return -1;
}
value = value * 83 + index;
}
return value;
}
void decodeDC(int value, Color *color)
{
color->r = sRGBToLinear(value >> 16);
color->g = sRGBToLinear((value >> 8) & 255);
color->b = sRGBToLinear(value & 255);
}
void decodeAC(int value, float maximumValue, Color *color)
{
int quantR = (int)floorf(value / (19 * 19));
int quantG = (int)floorf(value / 19) % 19;
int quantB = (int)value % 19;
color->r = signPow(((float)quantR - 9) / 9, 2.0) * maximumValue;
color->g = signPow(((float)quantG - 9) / 9, 2.0) * maximumValue;
color->b = signPow(((float)quantB - 9) / 9, 2.0) * maximumValue;
}
int decodeToArray(const char *blurhash, int width, int height, int punch, int nChannels, uint8_t *pixelArray)
{
if (!isValidBlurhash(blurhash)) {
return -1;
}
if (punch < 1) {
punch = 1;
}
int sizeFlag = decodeToInt(blurhash, 0, 1);
int numY = (int)floorf(sizeFlag / 9) + 1;
int numX = (sizeFlag % 9) + 1;
int iter = 0;
Color color;
int quantizedMaxValue = decodeToInt(blurhash, 1, 2);
if (quantizedMaxValue == -1) {
return -1;
}
const float maxValue = ((float)(quantizedMaxValue + 1)) / 166;
const int colors_size = numX * numY;
std::vector<Color> colors(colors_size, {0, 0, 0});
for (iter = 0; iter < colors_size; iter++) {
if (iter == 0) {
int value = decodeToInt(blurhash, 2, 6);
if (value == -1) {
return -1;
}
decodeDC(value, &color);
colors[iter] = color;
} else {
int value = decodeToInt(blurhash, 4 + iter * 2, 6 + iter * 2);
if (value == -1) {
return -1;
}
decodeAC(value, maxValue * punch, &color);
colors[iter] = color;
}
}
int bytesPerRow = width * nChannels;
int x = 0, y = 0, i = 0, j = 0;
int intR = 0, intG = 0, intB = 0;
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
float r = 0, g = 0, b = 0;
for (j = 0; j < numY; j++) {
for (i = 0; i < numX; i++) {
float basics = cos((M_PI * x * i) / width) * cos((M_PI * y * j) / height);
int idx = i + j * numX;
r += colors[idx].r * basics;
g += colors[idx].g * basics;
b += colors[idx].b * basics;
}
}
intR = linearTosRGB(r);
intG = linearTosRGB(g);
intB = linearTosRGB(b);
pixelArray[nChannels * x + 0 + y * bytesPerRow] = clampToUByte(&intR);
pixelArray[nChannels * x + 1 + y * bytesPerRow] = clampToUByte(&intG);
pixelArray[nChannels * x + 2 + y * bytesPerRow] = clampToUByte(&intB);
if (nChannels == 4) {
pixelArray[nChannels * x + 3 + y * bytesPerRow] = 255;
}
}
}
return 0;
}
}
uint8_t *decode(const char *blurhash, int width, int height, int punch, int nChannels)
{
int bytesPerRow = width * nChannels;
uint8_t *pixelArray = createByteArray(bytesPerRow * height);
if (decodeToArray(blurhash, width, height, punch, nChannels, pixelArray) == -1) {
return nullptr;
}
return pixelArray;
}
bool isValidBlurhash(const char *blurhash)
{
const int hashLength = strlen(blurhash);
if (!blurhash || strlen(blurhash) < 6) {
return false;
}
int sizeFlag = decodeToInt(blurhash, 0, 1);
int numY = (int)floorf(sizeFlag / 9) + 1;
int numX = (sizeFlag % 9) + 1;
return hashLength == 4 + 2 * numX * numY;
}

28
src/app/blurhash.h Normal file
View File

@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2018 Wolt Enterprises
// SPDX-License-Identifier: MIT
#pragma once
#include <stdint.h>
/**
* @brief Returns the pixel array of the result image given the blurhash string.
*
* @param blurhash a string representing the blurhash to be decoded.
* @param width the width of the resulting image.
* @param height the height of the resulting image.
* @param punch the factor to improve the contrast, default = 1.
* @param nChannels the number of channels in the resulting image array, 3 = RGB, 4 = RGBA.
*
* @return A pointer to memory region where pixels are stored in (H, W, C) format.
*/
uint8_t *decode(const char *blurhash, int width, int height, int punch, int nChannels);
/**
* @brief Checks if the Blurhash is valid or not.
*
* @param blurhash a string representing the blurhash.
*
* @return A bool (true if it is a valid blurhash, else false).
*/
bool isValidBlurhash(const char *blurhash);

View File

@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "blurhashimageprovider.h"
#include <QImage>
#include <QString>
#include "blurhash.h"
BlurhashImageProvider::BlurhashImageProvider()
: QQuickImageProvider(QQuickImageProvider::Image)
{
}
QImage BlurhashImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
if (id.isEmpty()) {
return QImage();
}
*size = requestedSize;
if (size->width() == -1) {
size->setWidth(256);
}
if (size->height() == -1) {
size->setHeight(256);
}
auto data = decode(QUrl::fromPercentEncoding(id.toLatin1()).toLatin1().data(), size->width(), size->height(), 1, 3);
QImage image(data, size->width(), size->height(), size->width() * 3, QImage::Format_RGB888, free, data);
return image;
}

View File

@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <QQuickImageProvider>
/**
* @class BlurhashImageProvider
*
* A QQuickImageProvider for blurhashes.
*
* @sa QQuickImageProvider
*/
class BlurhashImageProvider : public QQuickImageProvider
{
public:
BlurhashImageProvider();
/**
* @brief Return an image for a given ID.
*
* @sa QQuickImageProvider::requestImage
*/
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
};

407
src/app/controller.cpp Normal file
View File

@@ -0,0 +1,407 @@
// SPDX-FileCopyrightText: 2018-2019 Black Hat <bhat@encom.eu.org>
// SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-3.0-only
#include "controller.h"
#include <Quotient/connection.h>
#include <qt6keychain/keychain.h>
#include <KLocalizedString>
#include <QGuiApplication>
#include <QTimer>
#include <signal.h>
#include <Quotient/csapi/notifications.h>
#include <Quotient/events/roommemberevent.h>
#include <Quotient/qt_connection_util.h>
#include <Quotient/settings.h>
#include "accountmanager.h"
#include "enums/roomsortparameter.h"
#include "mediasizehelper.h"
#include "models/actionsmodel.h"
#include "models/messagemodel.h"
#include "models/pushrulemodel.h"
#include "models/roomlistmodel.h"
#include "models/roomtreemodel.h"
#include "neochatconfig.h"
#include "neochatconnection.h"
#include "neochatroom.h"
#include "notificationsmanager.h"
#include "proxycontroller.h"
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
#include "trayicon.h"
#elif !defined(Q_OS_ANDROID)
#include "trayicon_sni.h"
#endif
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
#ifndef Q_OS_ANDROID
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusMessage>
#endif
#endif
#ifdef HAVE_KUNIFIEDPUSH
#include <kunifiedpush/connector.h>
#endif
using namespace Quotient;
static std::function<bool(const Quotient::RoomEvent *)> hiddenEventFilter = [](const RoomEvent *event) -> bool {
if (event->isStateEvent() && !NeoChatConfig::showStateEvent()) {
return true;
}
if (auto roomMemberEvent = eventCast<const RoomMemberEvent>(event)) {
if ((roomMemberEvent->isJoin() || roomMemberEvent->isLeave()) && !NeoChatConfig::showLeaveJoinEvent()) {
return true;
} else if (roomMemberEvent->isRename() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::showRename()) {
return true;
} else if (roomMemberEvent->isAvatarUpdate() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::showAvatarUpdate()) {
return true;
}
}
return false;
};
Controller::Controller(QObject *parent)
: QObject(parent)
{
Connection::setRoomType<NeoChatRoom>();
Connection::setDirectChatEncryptionDefault(NeoChatConfig::preferUsingEncryption());
connect(NeoChatConfig::self(), &NeoChatConfig::PreferUsingEncryptionChanged, this, [] {
Connection::setDirectChatEncryptionDefault(NeoChatConfig::preferUsingEncryption());
});
NeoChatConnection::setGlobalUrlPreviewDefault(NeoChatConfig::showLinkPreview());
connect(NeoChatConfig::self(), &NeoChatConfig::ShowLinkPreviewChanged, this, [this] {
NeoChatConnection::setGlobalUrlPreviewDefault(NeoChatConfig::showLinkPreview());
Q_EMIT globalUrlPreviewDefaultChanged();
});
NeoChatConnection::setKeywordPushRuleDefault(static_cast<PushRuleAction::Action>(NeoChatConfig::keywordPushRuleDefault()));
connect(NeoChatConfig::self(), &NeoChatConfig::KeywordPushRuleDefaultChanged, this, [] {
NeoChatConnection::setKeywordPushRuleDefault(static_cast<PushRuleAction::Action>(NeoChatConfig::keywordPushRuleDefault()));
});
ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit());
connect(NeoChatConfig::self(), &NeoChatConfig::AllowQuickEditChanged, this, []() {
ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit());
});
MessageModel::setHiddenFilter(hiddenEventFilter);
RoomListModel::setHiddenFilter(hiddenEventFilter);
RoomTreeModel::setHiddenFilter(hiddenEventFilter);
MediaSizeHelper::setMaxSize(NeoChatConfig::mediaMaxWidth(), NeoChatConfig::mediaMaxHeight());
connect(NeoChatConfig::self(), &NeoChatConfig::MediaMaxWidthChanged, this, []() {
MediaSizeHelper::setMaxSize(NeoChatConfig::mediaMaxWidth(), NeoChatConfig::mediaMaxHeight());
});
connect(NeoChatConfig::self(), &NeoChatConfig::MediaMaxHeightChanged, this, []() {
MediaSizeHelper::setMaxSize(NeoChatConfig::mediaMaxWidth(), NeoChatConfig::mediaMaxHeight());
});
RoomSortParameter::setSortOrder(static_cast<RoomSortOrder::Order>(NeoChatConfig::sortOrder()));
connect(NeoChatConfig::self(), &NeoChatConfig::SortOrderChanged, this, []() {
RoomSortParameter::setSortOrder(static_cast<RoomSortOrder::Order>(NeoChatConfig::sortOrder()));
});
QList<RoomSortParameter::Parameter> configParamList;
const auto intList = NeoChatConfig::customSortOrder();
std::transform(intList.constBegin(), intList.constEnd(), std::back_inserter(configParamList), [](int param) {
return static_cast<RoomSortParameter::Parameter>(param);
});
RoomSortParameter::setCustomSortOrder(configParamList);
connect(NeoChatConfig::self(), &NeoChatConfig::CustomSortOrderChanged, this, []() {
QList<RoomSortParameter::Parameter> configParamList;
const auto intList = NeoChatConfig::customSortOrder();
std::transform(intList.constBegin(), intList.constEnd(), std::back_inserter(configParamList), [](int param) {
return static_cast<RoomSortParameter::Parameter>(param);
});
RoomSortParameter::setCustomSortOrder(configParamList);
});
ProxyController::instance().setApplicationProxy();
#ifndef Q_OS_ANDROID
setQuitOnLastWindowClosed();
connect(NeoChatConfig::self(), &NeoChatConfig::SystemTrayChanged, this, &Controller::setQuitOnLastWindowClosed);
#endif
QObject::connect(QGuiApplication::instance(), &QCoreApplication::aboutToQuit, QGuiApplication::instance(), [this] {
delete m_trayIcon;
NeoChatConfig::self()->save();
});
#ifndef Q_OS_WINDOWS
const auto unixExitHandler = [](int) -> void {
QCoreApplication::quit();
};
const int quitSignals[] = {SIGQUIT, SIGINT, SIGTERM, SIGHUP};
sigset_t blockingMask;
sigemptyset(&blockingMask);
for (const auto sig : quitSignals) {
sigaddset(&blockingMask, sig);
}
struct sigaction sa;
sa.sa_handler = unixExitHandler;
sa.sa_mask = blockingMask;
sa.sa_flags = 0;
for (auto sig : quitSignals) {
sigaction(sig, &sa, nullptr);
}
#endif
#ifdef HAVE_KUNIFIEDPUSH
auto connector = new KUnifiedPush::Connector(u"org.kde.neochat"_s);
connect(connector, &KUnifiedPush::Connector::endpointChanged, this, [this](const QString &endpoint) {
if (!m_accountManager) {
return;
}
m_endpoint = endpoint;
for (auto &quotientConnection : m_accountManager->accounts()->accounts()) {
auto connection = dynamic_cast<NeoChatConnection *>(quotientConnection);
connection->setupPushNotifications(endpoint);
}
});
connector->registerClient(
i18nc("The reason for using push notifications, as in: '[Push notifications are used for] Receiving notifications for new messages'",
"Receiving notifications for new messages"));
#endif
}
Controller &Controller::instance()
{
static Controller _instance;
return _instance;
}
void Controller::setAccountManager(AccountManager *manager)
{
if (manager == m_accountManager) {
return;
}
if (m_accountManager) {
m_accountManager->disconnect(this);
}
m_accountManager = manager;
if (m_accountManager) {
connect(m_accountManager, &AccountManager::errorOccured, this, &Controller::errorOccured);
connect(m_accountManager, &AccountManager::accountsLoadingChanged, this, &Controller::accountsLoadingChanged);
connect(m_accountManager, &AccountManager::connectionAdded, this, &Controller::initConnection);
connect(m_accountManager, &AccountManager::connectionDropped, this, &Controller::teardownConnection);
connect(m_accountManager, &AccountManager::activeConnectionChanged, this, &Controller::initActiveConnection);
}
}
void Controller::initConnection(NeoChatConnection *connection)
{
if (!connection) {
return;
}
connect(
connection,
&NeoChatConnection::syncDone,
this,
[this, connection] {
if (!m_endpoint.isEmpty()) {
connection->setupPushNotifications(m_endpoint);
}
},
Qt::SingleShotConnection);
connect(connection, &NeoChatConnection::syncDone, this, [this, connection]() {
m_notificationsManager.handleNotifications(connection);
});
connect(this, &Controller::globalUrlPreviewDefaultChanged, connection, &NeoChatConnection::globalUrlPreviewEnabledChanged);
Q_EMIT connectionAdded(connection);
}
void Controller::teardownConnection(NeoChatConnection *connection)
{
if (!connection) {
return;
}
connection->disconnect(this);
Q_EMIT connectionDropped(connection);
}
void Controller::initActiveConnection(NeoChatConnection *oldConnection, NeoChatConnection *newConnection)
{
if (oldConnection) {
oldConnection->disconnect(this);
}
if (newConnection) {
connect(newConnection, &NeoChatConnection::errorOccured, this, &Controller::errorOccured);
connect(newConnection, &NeoChatConnection::badgeNotificationCountChanged, this, &Controller::updateBadgeNotificationCount);
newConnection->refreshBadgeNotificationCount();
}
Q_EMIT activeConnectionChanged(newConnection);
}
bool Controller::supportSystemTray() const
{
#ifdef Q_OS_ANDROID
return false;
#else
auto de = QString::fromLatin1(qgetenv("XDG_CURRENT_DESKTOP"));
return de != u"GNOME"_s && de != u"Pantheon"_s;
#endif
}
void Controller::setQuitOnLastWindowClosed()
{
#ifndef Q_OS_ANDROID
if (supportSystemTray() && NeoChatConfig::self()->systemTray()) {
m_trayIcon = new TrayIcon(this);
m_trayIcon->show();
} else {
if (m_trayIcon) {
delete m_trayIcon;
m_trayIcon = nullptr;
}
}
#endif
}
NeoChatConnection *Controller::activeConnection() const
{
if (!m_accountManager) {
return nullptr;
}
return m_accountManager->activeConnection();
}
void Controller::setActiveConnection(NeoChatConnection *connection)
{
if (!m_accountManager) {
return;
}
m_accountManager->setActiveConnection(connection);
}
QStringList Controller::accountsLoading() const
{
if (!m_accountManager) {
return {};
}
return m_accountManager->accountsLoading();
}
void Controller::listenForNotifications()
{
#ifdef HAVE_KUNIFIEDPUSH
auto connector = new KUnifiedPush::Connector(u"org.kde.neochat"_s);
auto timer = new QTimer();
connect(timer, &QTimer::timeout, qGuiApp, &QGuiApplication::quit);
connect(connector, &KUnifiedPush::Connector::messageReceived, [timer](const QByteArray &data) {
instance().m_notificationsManager.postPushNotification(data);
timer->stop();
});
// Wait five seconds to see if we received any messages or this happened to be an erroneous activation.
// Otherwise, messageReceived is never activated, and this daemon could stick around forever.
timer->start(5000);
connector->registerClient(i18n("Receiving push notifications"));
#endif
}
void Controller::clearInvitationNotification(const QString &roomId)
{
m_notificationsManager.clearInvitationNotification(roomId);
}
void Controller::updateBadgeNotificationCount(int count)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
#ifndef Q_OS_ANDROID
// copied from Telegram desktop
const auto launcherUrl = "application://org.kde.neochat.desktop"_L1;
// Gnome requires that count is a 64bit integer
const qint64 counterSlice = std::min(count, 9999);
QVariantMap dbusUnityProperties;
if (counterSlice > 0) {
dbusUnityProperties["count"_L1] = counterSlice;
dbusUnityProperties["count-visible"_L1] = true;
} else {
dbusUnityProperties["count-visible"_L1] = false;
}
auto signal = QDBusMessage::createSignal("/com/canonical/unity/launcherentry/neochat"_L1, "com.canonical.Unity.LauncherEntry"_L1, "Update"_L1);
signal.setArguments({launcherUrl, dbusUnityProperties});
QDBusConnection::sessionBus().send(signal);
#endif // Q_OS_ANDROID
#else
qGuiApp->setBadgeNumber(count);
#endif // QT_VERSION_CHECK(6, 6, 0)
}
bool Controller::isFlatpak() const
{
#ifdef NEOCHAT_FLATPAK
return true;
#else
return false;
#endif
}
AccountRegistry *Controller::accounts()
{
return m_accountManager->accounts();
}
QString Controller::loadFileContent(const QString &path) const
{
QUrl url(path);
QFile file(url.isLocalFile() ? url.toLocalFile() : url.toString());
file.open(QFile::ReadOnly);
return QString::fromLatin1(file.readAll());
}
void Controller::removeConnection(const QString &userId)
{
m_accountManager->dropConnection(userId);
}
void Controller::revertToDefaultConfig()
{
const auto config = NeoChatConfig::self();
config->setDefaults();
config->save();
}
bool Controller::isImageShown(const QString &eventId)
{
return m_shownImages.contains(eventId);
}
void Controller::markImageShown(const QString &eventId)
{
m_shownImages.append(eventId);
}
#include "moc_controller.cpp"

134
src/app/controller.h Normal file
View File

@@ -0,0 +1,134 @@
// SPDX-FileCopyrightText: 2018-2019 Black Hat <bhat@encom.eu.org>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <QObject>
#include <QQmlEngine>
#include "accountmanager.h"
#include "neochatconnection.h"
#include "notificationsmanager.h"
#include <Quotient/accountregistry.h>
class TrayIcon;
namespace QKeychain
{
class ReadPasswordJob;
}
/**
* @class Controller
*
* A singleton class designed to help manage the application.
*
* There are also a bunch of helper functions that currently don't fit anywhere
* else.
*/
class Controller : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
/**
* @brief The current connection for the rest of NeoChat to use.
*/
Q_PROPERTY(NeoChatConnection *activeConnection READ activeConnection WRITE setActiveConnection NOTIFY activeConnectionChanged)
/**
* @brief Whether the OS NeoChat is running on supports sytem tray icons.
*/
Q_PROPERTY(bool supportSystemTray READ supportSystemTray CONSTANT)
/**
* @brief Whether NeoChat is running as a flatpak.
*
* This is the only way to gate NeoChat features in flatpaks in QML.
*/
Q_PROPERTY(bool isFlatpak READ isFlatpak CONSTANT)
Q_PROPERTY(QStringList accountsLoading READ accountsLoading NOTIFY accountsLoadingChanged)
public:
static Controller &instance();
static Controller *create(QQmlEngine *engine, QJSEngine *)
{
engine->setObjectOwnership(&instance(), QQmlEngine::CppOwnership);
return &instance();
}
void setAccountManager(AccountManager *manager);
[[nodiscard]] NeoChatConnection *activeConnection() const;
void setActiveConnection(NeoChatConnection *connection);
QStringList accountsLoading() const;
[[nodiscard]] bool supportSystemTray() const;
bool isFlatpak() const;
/**
* @brief Start listening for notifications in dbus-activated mode.
* These notifications will quit the application when closed.
*/
static void listenForNotifications();
/**
* @brief Clear an existing invite notification for the given room.
*
* Nothing happens if the given room doesn't have an invite notification.
*/
Q_INVOKABLE void clearInvitationNotification(const QString &roomId);
Q_INVOKABLE QString loadFileContent(const QString &path) const;
Quotient::AccountRegistry *accounts();
Q_INVOKABLE void removeConnection(const QString &userId);
/**
* @brief Revert all configuration values to their default.
*
* The parameters along with their defaults are specified in the config file
* neochatconfig.kcfg.
*/
Q_INVOKABLE void revertToDefaultConfig();
Q_INVOKABLE bool isImageShown(const QString &eventId);
Q_INVOKABLE void markImageShown(const QString &eventId);
private:
explicit Controller(QObject *parent = nullptr);
QPointer<AccountManager> m_accountManager;
void initConnection(NeoChatConnection *connection);
void teardownConnection(NeoChatConnection *connection);
void initActiveConnection(NeoChatConnection *oldConnection, NeoChatConnection *newConnection);
QPointer<NeoChatConnection> m_connection;
TrayIcon *m_trayIcon = nullptr;
QString m_endpoint;
QStringList m_shownImages;
NotificationsManager m_notificationsManager;
private Q_SLOTS:
void setQuitOnLastWindowClosed();
void updateBadgeNotificationCount(int count);
Q_SIGNALS:
/**
* @brief Request a error message be shown to the user.
*/
void errorOccured(const QString &error);
void connectionAdded(NeoChatConnection *connection);
void connectionDropped(NeoChatConnection *connection);
void activeConnectionChanged(NeoChatConnection *connection);
void accountsLoadingChanged();
void globalUrlPreviewDefaultChanged();
};

39
src/app/fakerunner.cpp Normal file
View File

@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include "fakerunner.h"
#include <QCoreApplication>
#include <QDBusMetaType>
Q_SCRIPTABLE RemoteActions FakeRunner::Actions()
{
QCoreApplication::quit();
return {};
}
Q_SCRIPTABLE RemoteMatches FakeRunner::Match(const QString &searchTerm)
{
Q_UNUSED(searchTerm);
QCoreApplication::quit();
return {};
}
Q_SCRIPTABLE void FakeRunner::Run(const QString &id, const QString &actionId)
{
Q_UNUSED(id);
Q_UNUSED(actionId);
QCoreApplication::quit();
}
FakeRunner::FakeRunner()
: QObject()
{
qDBusRegisterMetaType<RemoteMatch>();
qDBusRegisterMetaType<RemoteMatches>();
qDBusRegisterMetaType<RemoteAction>();
qDBusRegisterMetaType<RemoteActions>();
qDBusRegisterMetaType<RemoteImage>();
}
#include "moc_fakerunner.cpp"

31
src/app/fakerunner.h Normal file
View File

@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#pragma once
#include <QDBusContext>
#include "runner.h"
/**
* This is a close-to-identical copy of the regular Runner interface,
* only used when activated for push notifications. This stubs it out so
* Plasma Search and Kickoff doesn't accidentally activate the push notification
* service.
*
* @sa Runner
*/
class FakeRunner : public QObject, protected QDBusContext
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.krunner1")
public:
Q_SCRIPTABLE RemoteActions Actions();
Q_SCRIPTABLE RemoteMatches Match(const QString &searchTerm);
Q_SCRIPTABLE void Run(const QString &id, const QString &actionId);
FakeRunner();
};

48
src/app/foreigntypes.h Normal file
View File

@@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <QQmlEngine>
#include <Quotient/accountregistry.h>
#include <Quotient/e2ee/sssshandler.h>
#include <Quotient/keyimport.h>
#include <Quotient/keyverificationsession.h>
#include <Quotient/roommember.h>
#include "controller.h"
#include "neochatconfig.h"
struct ForeignAccountRegistry {
Q_GADGET
QML_FOREIGN(Quotient::AccountRegistry)
QML_NAMED_ELEMENT(AccountRegistry)
QML_SINGLETON
public:
static Quotient::AccountRegistry *create(QQmlEngine *, QJSEngine *)
{
QQmlEngine::setObjectOwnership(Controller::instance().accounts(), QQmlEngine::CppOwnership);
return Controller::instance().accounts();
}
};
struct ForeignKeyVerificationSession {
Q_GADGET
QML_FOREIGN(Quotient::KeyVerificationSession)
QML_NAMED_ELEMENT(KeyVerificationSession)
QML_UNCREATABLE("")
};
struct ForeignSSSSHandler {
Q_GADGET
QML_FOREIGN(Quotient::SSSSHandler)
QML_NAMED_ELEMENT(SSSSHandler)
};
struct ForeignKeyImport {
Q_GADGET
QML_SINGLETON
QML_FOREIGN(Quotient::KeyImport)
QML_NAMED_ELEMENT(KeyImport)
};

View File

@@ -0,0 +1,121 @@
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include "identityserverhelper.h"
#include <QNetworkReply>
#include <KLocalizedString>
#include <Quotient/networkaccessmanager.h>
#include "neochatconnection.h"
using namespace Qt::StringLiterals;
IdentityServerHelper::IdentityServerHelper(QObject *parent)
: QObject(parent)
{
}
NeoChatConnection *IdentityServerHelper::connection() const
{
return m_connection;
}
void IdentityServerHelper::setConnection(NeoChatConnection *connection)
{
if (m_connection == connection) {
return;
}
if (m_connection != nullptr) {
m_connection->disconnect(this);
}
m_connection = connection;
Q_EMIT connectionChanged();
}
QString IdentityServerHelper::url() const
{
return m_url;
}
void IdentityServerHelper::setUrl(const QString &url)
{
if (url == m_url) {
return;
}
m_url = url;
Q_EMIT urlChanged();
checkUrl();
}
IdentityServerHelper::IdServerStatus IdentityServerHelper::status() const
{
return m_status;
}
void IdentityServerHelper::checkUrl()
{
if (m_idServerCheckRequest != nullptr) {
m_idServerCheckRequest->abort();
m_idServerCheckRequest.clear();
}
if (m_url == m_connection->identityServer().toString()) {
m_status = Match;
Q_EMIT statusChanged();
return;
}
if (m_url.isEmpty()) {
m_status = Valid;
Q_EMIT statusChanged();
return;
}
const auto requestUrl = QUrl(m_url + u"/_matrix/identity/v2"_s);
if (!(requestUrl.scheme() == u"https"_s || requestUrl.scheme() == u"http"_s)) {
m_status = Invalid;
Q_EMIT statusChanged();
return;
}
QNetworkRequest request(requestUrl);
m_idServerCheckRequest = Quotient::NetworkAccessManager::instance()->get(request);
connect(m_idServerCheckRequest, &QNetworkReply::finished, this, [this]() {
if (m_idServerCheckRequest->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200) {
m_status = Valid;
Q_EMIT statusChanged();
} else {
m_status = Invalid;
Q_EMIT statusChanged();
}
});
}
void IdentityServerHelper::setIdentityServer()
{
if (m_url == m_connection->identityServer().toString()) {
return;
}
m_connection->setAccountData(u"m.identity_server"_s, {{"base_url"_L1, m_url}});
m_status = Ready;
Q_EMIT statusChanged();
}
void IdentityServerHelper::clearIdentityServer()
{
if (m_connection->identityServer().isEmpty()) {
return;
}
m_connection->setAccountData(u"m.identity_server"_s, {{"base_url"_L1, QString()}});
m_status = Ready;
Q_EMIT statusChanged();
}
#include "moc_identityserverhelper.cpp"

View File

@@ -0,0 +1,88 @@
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#pragma once
#include <QObject>
#include <QQmlEngine>
#include <Quotient/jobs/basejob.h>
class NeoChatConnection;
/**
* @class IdentityServerHelper
*
* This class is designed to help the process of setting an identity server for the account.
* It will manage the various stages of verification and authentication.
*/
class IdentityServerHelper : public QObject
{
Q_OBJECT
QML_ELEMENT
/**
* @brief The connection to add a 3PID to.
*/
Q_PROPERTY(NeoChatConnection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
/**
* @brief The URL for the desired server.
*/
Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
/**
* @brief The current status.
*/
Q_PROPERTY(IdServerStatus status READ status NOTIFY statusChanged)
public:
/**
* @brief The current status for adding an identity server
*/
enum IdServerStatus {
Ready, /**< The process is ready to start. I.e. there is no ongoing attempt to set a new server. */
Valid, /**< The server URL is valid. */
Invalid, /**< The server URL is invalid. */
Match, /**< The server URL is the one that is already configured. */
Other, /**< An unknown problem occurred. */
};
Q_ENUM(IdServerStatus)
explicit IdentityServerHelper(QObject *parent = nullptr);
[[nodiscard]] NeoChatConnection *connection() const;
void setConnection(NeoChatConnection *connection);
[[nodiscard]] QString url() const;
void setUrl(const QString &url);
[[nodiscard]] IdServerStatus status() const;
/**
* @brief Set the current URL as the user's identity server.
*
* Will do nothing if the URL isn't a valid identity server.
*/
Q_INVOKABLE void setIdentityServer();
/**
* @brief Clear the user's identity server.
*/
Q_INVOKABLE void clearIdentityServer();
Q_SIGNALS:
void connectionChanged();
void urlChanged();
void statusChanged();
private:
QPointer<NeoChatConnection> m_connection;
IdServerStatus m_status = Ready;
QString m_url;
QPointer<QNetworkReply> m_idServerCheckRequest;
void checkUrl();
};

223
src/app/logger.cpp Normal file
View File

@@ -0,0 +1,223 @@
// SPDX-FileCopyrightText: 1997 Matthias Kalle Dalheimer <kalle@kde.org>
// SPDX-FileCopyrightText: 2002 Holger Freyther <freyther@kde.org>
// SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
// SPDX-FileCopyrightText: 2023 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "logger.h"
#include <QDateTime>
#include <QDir>
#include <QFileInfo>
#include <QLoggingCategory>
#include <QMutex>
#include <QStandardPaths>
using namespace Qt::StringLiterals;
static QLoggingCategory::CategoryFilter oldCategoryFilter = nullptr;
static QtMessageHandler oldHandler = nullptr;
static bool e2eeDebugEnabled = false;
class FileDebugStream : public QIODevice
{
Q_OBJECT
public:
FileDebugStream()
: mType(QtCriticalMsg)
{
open(WriteOnly);
}
bool isSequential() const override
{
return true;
}
qint64 readData(char *, qint64) override
{
return 0;
}
qint64 readLineData(char *, qint64) override
{
return 0;
}
qint64 writeData(const char *data, qint64 len) override
{
if (!mFileName.isEmpty()) {
QFile outputFile(mFileName);
outputFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Unbuffered);
outputFile.write(data, len);
outputFile.putChar('\n');
outputFile.close();
}
return len;
}
void setFileName(const QString &fileName)
{
mFileName = fileName;
}
void setType(QtMsgType type)
{
mType = type;
}
private:
QString mFileName;
QtMsgType mType;
};
class DebugPrivate
{
public:
DebugPrivate()
: origHandler(nullptr)
{
}
~DebugPrivate()
{
qInstallMessageHandler(origHandler);
file.close();
}
void log(QtMsgType type, const QMessageLogContext &context, const QString &message)
{
QMutexLocker locker(&mutex);
QByteArray buf;
QTextStream str(&buf);
str << QDateTime::currentDateTime().toString(Qt::ISODate) << u" ["_s;
switch (type) {
case QtDebugMsg:
str << u"DEBUG"_s;
break;
case QtInfoMsg:
str << u"INFO "_s;
break;
case QtWarningMsg:
str << u"WARN "_s;
break;
case QtFatalMsg:
str << u"FATAL"_s;
break;
case QtCriticalMsg:
str << u"CRITICAL"_s;
break;
}
str << u"] "_s << context.category << u": "_s;
if (context.file && *context.file && context.line) {
str << context.file << u":"_s << context.line << u": "_s;
}
if (context.function && *context.function) {
str << context.function << u": "_s;
}
str << message << u"\n"_s;
str.flush();
file.write(buf.constData(), buf.size());
file.flush();
if (oldHandler && (!context.category || (strcmp(context.category, "quotient.e2ee") != 0 || e2eeDebugEnabled))) {
oldHandler(type, context, message);
}
}
void setName(const QString &appName)
{
name = appName;
if (file.isOpen()) {
file.close();
}
const auto &filePath = u"%1%2%3"_s.arg(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), QDir::separator(), appName);
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QDir::separator());
auto entryList = dir.entryList({appName + u".*"_s});
std::sort(entryList.begin(), entryList.end(), [](const auto &left, const auto &right) {
auto leftIndex = left.split(u"."_s).last().toInt();
auto rightIndex = right.split(u"."_s).last().toInt();
return leftIndex > rightIndex;
});
for (const auto &entry : entryList) {
bool ok = false;
const auto index = entry.split(u"."_s).last().toInt(&ok);
if (!ok) {
continue;
}
QFileInfo info(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QDir::separator() + entry);
if (info.exists()) {
QFile file(info.absoluteFilePath());
if (index > 50) {
file.remove();
continue;
}
const auto &newName = u"%1.%2"_s.arg(filePath, QString::number(index + 1));
const auto success = file.copy(newName);
if (success) {
file.remove();
} else {
qFatal("Cannot rename log file '%s' to '%s': %s",
qUtf8Printable(file.fileName()),
qUtf8Printable(newName),
qUtf8Printable(file.errorString()));
}
}
}
QFileInfo finfo(filePath);
if (!finfo.absoluteDir().exists()) {
QDir().mkpath(finfo.absolutePath());
}
file.setFileName(filePath + u".0"_s);
file.open(QIODevice::WriteOnly | QIODevice::Unbuffered);
}
void setOrigHandler(QtMessageHandler origHandler_)
{
origHandler = origHandler_;
}
QMutex mutex;
QFile file;
QString name;
QtMessageHandler origHandler;
QByteArray loggingCategory;
};
Q_GLOBAL_STATIC(DebugPrivate, sInstance)
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
{
switch (type) {
case QtDebugMsg:
case QtInfoMsg:
case QtWarningMsg:
case QtCriticalMsg:
sInstance()->log(type, context, message);
break;
case QtFatalMsg:
sInstance()->log(QtInfoMsg, context, message);
}
}
void filter(QLoggingCategory *category)
{
if (qstrcmp(category->categoryName(), "quotient.e2ee") == 0) {
category->setEnabled(QtDebugMsg, true);
} else if (oldCategoryFilter) {
oldCategoryFilter(category);
}
}
void initLogging()
{
e2eeDebugEnabled = QLoggingCategory("quotient.e2ee", QtInfoMsg).isEnabled(QtDebugMsg);
oldCategoryFilter = QLoggingCategory::installFilter(filter);
oldHandler = qInstallMessageHandler(messageHandler);
sInstance->setOrigHandler(oldHandler);
sInstance->setName(u"neochat.log"_s);
}
#include "logger.moc"

9
src/app/logger.h Normal file
View File

@@ -0,0 +1,9 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
/**
* Initlalize logging to file and enables some additional categories, which will only be logged to the file
*/
void initLogging();

313
src/app/main.cpp Normal file
View File

@@ -0,0 +1,313 @@
// SPDX-FileCopyrightText: 2018-2019 Black Hat <bhat@encom.eu.org>
// SPDX-License-Identifier: GPL-3.0-only
#include <QCommandLineParser>
#include <QIcon>
#include <QNetworkDiskCache>
#include <QNetworkProxyFactory>
#include <QNetworkReply>
#include <QObject>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQmlNetworkAccessManagerFactory>
#include <QQuickStyle>
#include <QQuickWindow>
#include <QtQml/QQmlExtensionPlugin>
#include <Quotient/connection.h>
#ifdef Q_OS_ANDROID
#include <QGuiApplication>
#else
#include <QApplication>
#endif
#ifdef HAVE_WEBVIEW
#include <QtWebView>
#endif
#include <KAboutData>
#ifdef HAVE_KDBUSADDONS
#include <KDBusService>
#endif
#ifdef HAVE_WINDOWSYSTEM
#include <KWindowSystem>
#endif
#if __has_include("KCrash")
#include <KCrash>
#endif
#include <KIconTheme>
#include <KLocalizedContext>
#include <KLocalizedString>
#include "neochat-version.h"
#include <Quotient/networkaccessmanager.h>
#include "accountmanager.h"
#include "blurhashimageprovider.h"
#include "colorschemer.h"
#include "controller.h"
#include "logger.h"
#include "login.h"
#include "registration.h"
#include "roommanager.h"
#include "sharehandler.h"
#include "windowcontroller.h"
#ifdef HAVE_RUNNER
#include "runner.h"
#include <QDBusConnection>
#include <QDBusMetaType>
#endif
#if defined(HAVE_RUNNER) && defined(HAVE_KUNIFIEDPUSH)
#include "fakerunner.h"
#endif
#ifdef Q_OS_WINDOWS
#include <Windows.h>
#endif
using namespace Quotient;
void qml_register_types_org_kde_neochat();
class NetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory
{
QNetworkAccessManager *create(QObject *) override
{
auto nam = NetworkAccessManager::instance();
nam->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
nam->enableStrictTransportSecurityStore(true, QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + u"/hsts/"_s);
nam->setStrictTransportSecurityEnabled(true);
auto namDiskCache = new QNetworkDiskCache(nam);
namDiskCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + u"/nam/"_s);
nam->setCache(namDiskCache);
return nam;
}
};
static QWindow *windowFromEngine(QQmlApplicationEngine *engine)
{
const auto rootObjects = engine->rootObjects();
auto *window = qobject_cast<QQuickWindow *>(rootObjects.first());
Q_ASSERT(window);
return window;
}
#ifdef Q_OS_ANDROID
Q_DECL_EXPORT
#endif
int main(int argc, char *argv[])
{
KIconTheme::initTheme();
QNetworkProxyFactory::setUseSystemConfiguration(true);
#ifdef HAVE_WEBVIEW
QtWebView::initialize();
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi);
#endif
#ifdef Q_OS_ANDROID
QGuiApplication app(argc, argv);
QQuickStyle::setStyle(u"org.kde.breeze"_s);
#else
QIcon::setFallbackThemeName("breeze"_L1);
QApplication app(argc, argv);
// Default to org.kde.desktop style unless the user forces another style
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
QQuickStyle::setStyle(u"org.kde.desktop"_s);
}
#endif
#ifdef Q_OS_WINDOWS
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
QApplication::setStyle(u"breeze"_s);
QFont font(u"Segoe UI Emoji"_s);
font.setPointSize(10);
font.setHintingPreference(QFont::PreferNoHinting);
app.setFont(font);
#endif
KLocalizedString::setApplicationDomain(QByteArrayLiteral("neochat"));
QGuiApplication::setOrganizationName("KDE"_L1);
KAboutData about(u"neochat"_s,
i18n("NeoChat"),
QStringLiteral(NEOCHAT_VERSION_STRING),
i18n("Chat on Matrix"),
KAboutLicense::GPL_V3,
i18n("© 2018-2020 Black Hat, 2020-2025 KDE Community"));
about.addAuthor(i18n("Carl Schwan"), i18n("Maintainer"), u"carl@carlschwan.eu"_s, u"https://carlschwan.eu"_s, QUrl(u"https://carlschwan.eu/avatar.png"_s));
about.addAuthor(i18n("Tobias Fella"), i18n("Maintainer"), u"tobias.fella@kde.org"_s, u"https://tobiasfella.de"_s);
about.addAuthor(i18n("James Graham"), i18n("Maintainer"), u"james.h.graham@protonmail.com"_s);
about.addAuthor(i18n("Joshua Goins"),
i18n("Maintainer"),
u"josh@redstrate.com"_s,
u"https://redstrate.com/"_s,
QUrl(u"https://redstrate.com/rss-image.png"_s));
about.addCredit(i18n("Black Hat"), i18n("Original author of Spectral"), u"bhat@encom.eu.org"_s);
about.addCredit(i18n("Alexey Rusakov"), i18n("Maintainer of libQuotient"), u"Kitsune-Ral@users.sf.net"_s);
about.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
about.setOrganizationDomain("kde.org");
about.addComponent(u"libQuotient"_s,
i18n("A Qt library to write cross-platform clients for Matrix"),
i18nc("<version number> (built against <possibly different version number>)",
"%1 (built against %2)",
Quotient::versionString(),
QStringLiteral(Quotient_VERSION_STRING)),
u"https://github.com/quotient-im/libquotient"_s,
KAboutLicense::LGPL_V2_1);
KAboutData::setApplicationData(about);
QGuiApplication::setWindowIcon(QIcon::fromTheme(u"org.kde.neochat"_s));
#if __has_include("KCrash")
KCrash::initialize();
#endif
initLogging();
Connection::setEncryptionDefault(true);
Connection::setDirectChatEncryptionDefault(true);
#ifdef NEOCHAT_FLATPAK
// Copy over the included FontConfig configuration to the
// app's config dir:
QFile::copy(u"/app/etc/fonts/conf.d/99-noto-mono-color-emoji.conf"_s, u"/var/config/fontconfig/conf.d/99-noto-mono-color-emoji.conf"_s);
#endif
ColorSchemer colorScheme;
QCommandLineParser parser;
parser.setApplicationDescription(i18n("Client for the matrix communication protocol"));
parser.addPositionalArgument(u"urls"_s, i18n("Supports matrix: url scheme"));
parser.addOption(QCommandLineOption("ignore-ssl-errors"_L1, i18n("Ignore all SSL Errors, e.g., unsigned certificates.")));
QCommandLineOption testOption("test"_L1, i18n("Only used for autotests"));
testOption.setFlags(QCommandLineOption::HiddenFromHelp);
parser.addOption(testOption);
#ifdef HAVE_KUNIFIEDPUSH
QCommandLineOption dbusActivatedOption(u"dbus-activated"_s, i18n("Internal usage only."));
dbusActivatedOption.setFlags(QCommandLineOption::Flag::HiddenFromHelp);
parser.addOption(dbusActivatedOption);
#endif
QCommandLineOption shareOption(u"share"_s, i18n("Share a URL to Matrix"), u"text"_s);
parser.addOption(shareOption);
about.setupCommandLine(&parser);
parser.process(app);
about.processCommandLine(&parser);
#ifdef HAVE_KUNIFIEDPUSH
if (parser.isSet(dbusActivatedOption)) {
// We want to be replaceable by the main client
KDBusService service(KDBusService::Replace);
#ifdef HAVE_RUNNER
// If we are built with KRunner and KUnifiedPush support, we need to do something special.
// Because KRunner may call us on the D-Bus (under the same service name org.kde.neochat) then it may
// accidentally activate us for push notifications instead. If this happens, then immediately quit if the fake
// runner is called.
QDBusConnection::sessionBus().registerObject("/RoomRunner"_L1, new FakeRunner(), QDBusConnection::ExportScriptableContents);
#endif
Controller::listenForNotifications();
return QCoreApplication::exec();
}
#endif
#ifdef HAVE_KDBUSADDONS
KDBusService service(KDBusService::Unique);
#endif
const auto accountManager = std::make_unique<AccountManager>(parser.isSet("test"_L1));
Controller::instance().setAccountManager(accountManager.get());
LoginHelper::instance().setAccountManager(accountManager.get());
Registration::instance().setAccountManager(accountManager.get());
Q_IMPORT_QML_PLUGIN(org_kde_neochat_settingsPlugin)
Q_IMPORT_QML_PLUGIN(org_kde_neochat_roomsPlugin)
Q_IMPORT_QML_PLUGIN(org_kde_neochat_timelinePlugin)
Q_IMPORT_QML_PLUGIN(org_kde_neochat_devtoolsPlugin)
Q_IMPORT_QML_PLUGIN(org_kde_neochat_loginPlugin)
Q_IMPORT_QML_PLUGIN(org_kde_neochat_chatbarPlugin)
qml_register_types_org_kde_neochat();
qmlRegisterUncreatableMetaObject(Quotient::staticMetaObject, "Quotient", 1, 0, "JoinRule", u"Access to JoinRule enum only"_s);
QQmlApplicationEngine engine;
#ifdef HAVE_KDBUSADDONS
service.connect(&service,
&KDBusService::activateRequested,
&RoomManager::instance(),
[&engine](const QStringList &arguments, const QString &workingDirectory) {
Q_UNUSED(workingDirectory);
QWindow *window = windowFromEngine(&engine);
KWindowSystem::updateStartupId(window);
WindowController::instance().showAndRaiseWindow(QString());
// Open matrix uri
if (arguments.isEmpty()) {
return;
}
auto args = arguments;
args.removeFirst();
if (args.length() == 2 && args[0] == "--share"_L1) {
ShareHandler::instance().setText(args[1]);
return;
}
for (const auto &arg : args) {
RoomManager::instance().resolveResource(arg);
}
});
#endif
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
engine.setNetworkAccessManagerFactory(new NetworkAccessManagerFactory());
if (parser.isSet("ignore-ssl-errors"_L1)) {
QObject::connect(NetworkAccessManager::instance(), &QNetworkAccessManager::sslErrors, NetworkAccessManager::instance(), [](QNetworkReply *reply) {
reply->ignoreSslErrors();
});
}
if (parser.isSet("share"_L1)) {
ShareHandler::instance().setText(parser.value(shareOption));
}
engine.addImageProvider(u"blurhash"_s, new BlurhashImageProvider);
engine.loadFromModule("org.kde.neochat", "Main");
if (!parser.positionalArguments().isEmpty() && !parser.isSet("share"_L1)) {
RoomManager::instance().setUrlArgument(parser.positionalArguments()[0]);
}
#ifdef HAVE_RUNNER
auto runner = Runner::create(&engine, &engine);
QDBusConnection::sessionBus().registerObject("/RoomRunner"_L1, runner, QDBusConnection::ExportScriptableContents);
#endif
WindowController::instance().setWindow(windowFromEngine(&engine));
return app.exec();
}

11
src/app/mediamanager.cpp Normal file
View File

@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "mediamanager.h"
void MediaManager::startPlayback()
{
Q_EMIT playbackStarted();
}
#include "moc_mediamanager.cpp"

42
src/app/mediamanager.h Normal file
View File

@@ -0,0 +1,42 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <QObject>
#include <QQmlEngine>
/**
* @class MediaManager
*
* Manages media playback, like voice/audio messages, videos, etc.
*/
class MediaManager : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
public:
static MediaManager &instance()
{
static MediaManager _instance;
return _instance;
}
static MediaManager *create(QQmlEngine *, QJSEngine *)
{
QQmlEngine::setObjectOwnership(&instance(), QQmlEngine::CppOwnership);
return &instance();
}
/**
* @brief Notify other objects that media playback has started.
*/
Q_INVOKABLE void startPlayback();
Q_SIGNALS:
/**
* @brief Emitted when any media player starts playing. Other objects should stop / pause playback.
*/
void playbackStarted();
};

View File

@@ -0,0 +1,79 @@
// SPDX-FileCopyrightText: 2025 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "commonroomsmodel.h"
#include "jobs/neochatgetcommonroomsjob.h"
#include <QGuiApplication>
using namespace Quotient;
CommonRoomsModel::CommonRoomsModel(QObject *parent)
: QAbstractListModel(parent)
{
}
NeoChatConnection *CommonRoomsModel::connection() const
{
return m_connection;
}
void CommonRoomsModel::setConnection(NeoChatConnection *connection)
{
m_connection = connection;
Q_EMIT connectionChanged();
reload();
}
QString CommonRoomsModel::userId() const
{
return m_userId;
}
void CommonRoomsModel::setUserId(const QString &userId)
{
m_userId = userId;
Q_EMIT userIdChanged();
reload();
}
QVariant CommonRoomsModel::data(const QModelIndex &index, int roleName) const
{
Q_UNUSED(index)
Q_UNUSED(roleName)
return {};
}
int CommonRoomsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_commonRooms.size();
}
void CommonRoomsModel::reload()
{
if (!m_connection || m_userId.isEmpty()) {
return;
}
if (!m_connection->canCheckMutualRooms()) {
return;
}
// Checking if you have mutual rooms with yourself doesn't make sense and servers reject it too
if (m_connection->userId() == m_userId) {
return;
}
m_connection->callApi<NeochatGetCommonRoomsJob>(m_userId).then([this](const auto job) {
const auto &replyData = job->jsonData();
beginResetModel();
for (const auto &roomId : replyData[u"joined"_s].toArray()) {
m_commonRooms.push_back(roomId.toString());
}
endResetModel();
Q_EMIT countChanged();
});
}
#include "moc_commonroomsmodel.cpp"

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: 2025 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QAbstractListModel>
#include <QQmlEngine>
#include "neochatconnection.h"
#include "neochatroom.h"
#include <Quotient/events/roommessageevent.h>
#include <Quotient/roommember.h>
/**
* @brief Model to show the common or mutual rooms between you and another user.
*/
class CommonRoomsModel : public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(NeoChatConnection *connection WRITE setConnection READ connection NOTIFY connectionChanged REQUIRED)
Q_PROPERTY(QString userId WRITE setUserId READ userId NOTIFY userIdChanged REQUIRED)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
public:
enum Roles {
TextRole = Qt::DisplayRole,
LongitudeRole,
LatitudeRole,
AssetRole,
AuthorRole,
};
Q_ENUM(Roles)
explicit CommonRoomsModel(QObject *parent = nullptr);
[[nodiscard]] NeoChatConnection *connection() const;
void setConnection(NeoChatConnection *connection);
[[nodiscard]] QString userId() const;
void setUserId(const QString &userId);
[[nodiscard]] QVariant data(const QModelIndex &index, int roleName) const override;
[[nodiscard]] Q_INVOKABLE int rowCount(const QModelIndex &parent = {}) const override;
Q_SIGNALS:
void connectionChanged();
void userIdChanged();
void countChanged();
private:
void reload();
QPointer<NeoChatConnection> m_connection;
QString m_userId;
QList<QString> m_commonRooms;
};

View File

@@ -0,0 +1,164 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "notificationsmodel.h"
#include <Quotient/events/event.h>
#include <Quotient/uri.h>
#include "eventhandler.h"
#include "neochatroom.h"
using namespace Quotient;
NotificationsModel::NotificationsModel(QObject *parent)
: QAbstractListModel(parent)
{
}
int NotificationsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_notifications.count();
}
QVariant NotificationsModel::data(const QModelIndex &index, int role) const
{
auto row = index.row();
if (row < 0 || row >= m_notifications.count()) {
return {};
}
if (role == TextRole) {
return m_notifications[row].text;
}
if (role == RoomIdRole) {
return m_notifications[row].roomId;
}
if (role == AuthorName) {
return m_notifications[row].authorName;
}
if (role == AuthorAvatar) {
return m_notifications[row].authorAvatar;
}
if (role == RoomRole) {
return QVariant::fromValue(m_connection->room(m_notifications[row].roomId));
}
if (role == EventIdRole) {
return m_notifications[row].eventId;
}
if (role == RoomDisplayNameRole) {
return m_notifications[row].roomDisplayName;
}
if (role == UriRole) {
return Uri(m_notifications[row].roomId.toLatin1(), m_notifications[row].eventId.toLatin1()).toUrl();
}
return {};
}
QHash<int, QByteArray> NotificationsModel::roleNames() const
{
return {
{TextRole, "text"},
{RoomIdRole, "roomId"},
{AuthorName, "authorName"},
{AuthorAvatar, "authorAvatar"},
{RoomRole, "room"},
{EventIdRole, "eventId"},
{RoomDisplayNameRole, "roomDisplayName"},
{UriRole, "uri"},
};
}
NeoChatConnection *NotificationsModel::connection() const
{
return m_connection;
}
void NotificationsModel::setConnection(NeoChatConnection *connection)
{
if (m_connection) {
// disconnect things...
}
if (!connection) {
return;
}
m_connection = connection;
Q_EMIT connectionChanged();
connect(connection, &Connection::syncDone, this, [this]() {
loadData();
});
loadData();
}
void NotificationsModel::loadData()
{
Q_ASSERT(m_connection);
if (m_job || (m_notifications.size() && m_nextToken.isEmpty())) {
return;
}
m_job = m_connection->callApi<GetNotificationsJob>(m_nextToken);
Q_EMIT loadingChanged();
connect(m_job, &BaseJob::finished, this, [this]() {
m_nextToken = m_job->nextToken();
Q_EMIT nextTokenChanged();
for (const auto &notification : m_job->notifications()) {
if (std::any_of(notification.actions.constBegin(), notification.actions.constEnd(), [](const QVariant &it) {
if (it.canConvert<QVariantMap>()) {
auto map = it.toMap();
if (map["set_tweak"_L1] == "highlight"_L1) {
return true;
}
}
return false;
})) {
const auto &authorId = notification.event->fullJson()["sender"_L1].toString();
const auto &room = m_connection->room(notification.roomId);
if (!room) {
continue;
}
auto u = room->member(authorId).avatarUrl();
auto avatar = u.isEmpty() ? QUrl() : connection()->makeMediaUrl(u);
const auto &authorAvatar = avatar.isValid() && avatar.scheme() == u"mxc"_s ? avatar : QUrl();
const auto &roomEvent = eventCast<const RoomEvent>(notification.event.get());
beginInsertRows({}, m_notifications.length(), m_notifications.length());
m_notifications += Notification{
.roomId = notification.roomId,
.text = room->member(authorId).htmlSafeDisplayName() + (roomEvent->is<StateEvent>() ? u" "_s : u": "_s)
+ EventHandler::plainBody(dynamic_cast<NeoChatRoom *>(room), roomEvent, true),
.authorName = room->member(authorId).htmlSafeDisplayName(),
.authorAvatar = authorAvatar,
.eventId = roomEvent->id(),
.roomDisplayName = room->displayName(),
};
endInsertRows();
}
}
m_job = nullptr;
Q_EMIT loadingChanged();
});
}
bool NotificationsModel::canFetchMore(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return !m_nextToken.isEmpty();
}
void NotificationsModel::fetchMore(const QModelIndex &parent)
{
Q_UNUSED(parent);
loadData();
}
bool NotificationsModel::loading() const
{
return m_job;
}
QString NotificationsModel::nextToken() const
{
return m_nextToken;
}
#include "moc_notificationsmodel.cpp"

View File

@@ -0,0 +1,68 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include "neochatconnection.h"
#include <QAbstractListModel>
#include <QPointer>
#include <QQmlEngine>
#include <QVariant>
#include <Quotient/csapi/notifications.h>
class NotificationsModel : public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(NeoChatConnection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
Q_PROPERTY(QString nextToken READ nextToken NOTIFY nextTokenChanged)
public:
enum Roles {
TextRole = Qt::DisplayRole,
RoomIdRole,
AuthorName,
AuthorAvatar,
RoomRole,
EventIdRole,
RoomDisplayNameRole,
UriRole,
};
Q_ENUM(Roles);
struct Notification {
QString roomId;
QString text;
QString authorName;
QUrl authorAvatar;
QString eventId;
QString roomDisplayName;
};
NotificationsModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
bool canFetchMore(const QModelIndex &parent) const override;
void fetchMore(const QModelIndex &parent) override;
NeoChatConnection *connection() const;
void setConnection(NeoChatConnection *connection);
bool loading() const;
QString nextToken() const;
Q_SIGNALS:
void connectionChanged();
void loadingChanged();
void nextTokenChanged();
private:
QPointer<NeoChatConnection> m_connection;
void loadData();
QList<Notification> m_notifications;
QString m_nextToken;
QPointer<Quotient::GetNotificationsJob> m_job;
};

View File

@@ -0,0 +1,182 @@
// SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include "serverlistmodel.h"
#include <QDebug>
#include <KConfig>
#include <KConfigGroup>
#include <KSharedConfig>
#include "neochatconnection.h"
using namespace Qt::StringLiterals;
ServerListModel::ServerListModel(QObject *parent)
: QAbstractListModel(parent)
{
}
QVariant ServerListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
return {};
}
if (index.row() >= m_servers.count()) {
qDebug() << "ServerListModel, something's wrong: index.row() >= m_notificationRules.count()";
return {};
}
if (role == UrlRole) {
return m_servers.at(index.row()).url;
}
if (role == IsHomeServerRole) {
return m_servers.at(index.row()).isHomeServer;
}
if (role == IsAddServerDelegateRole) {
return m_servers.at(index.row()).isAddServerDelegate;
}
if (role == IsDeletableRole) {
return m_servers.at(index.row()).isDeletable;
}
return {};
}
int ServerListModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_servers.count();
}
void ServerListModel::checkServer(const QString &url)
{
const auto stateConfig = KSharedConfig::openStateConfig();
const KConfigGroup serverGroup = stateConfig->group(u"Servers"_s);
if (!serverGroup.hasKey(url)) {
if (Quotient::isJobPending(m_checkServerJob)) {
m_checkServerJob->abandon();
}
m_checkServerJob = m_connection->callApi<Quotient::QueryPublicRoomsJob>(url, 1);
connect(m_checkServerJob, &Quotient::BaseJob::success, this, [this, url] {
Q_EMIT serverCheckComplete(url, true);
});
}
}
void ServerListModel::addServer(const QString &url)
{
const auto stateConfig = KSharedConfig::openStateConfig();
KConfigGroup serverGroup = stateConfig->group(u"Servers"_s);
if (!serverGroup.hasKey(url)) {
Server newServer = Server{
url,
false,
false,
true,
};
beginInsertRows(QModelIndex(), m_servers.count() - 1, m_servers.count() - 1);
m_servers.insert(rowCount() - 1, newServer);
endInsertRows();
}
serverGroup.writeEntry(url, url);
stateConfig->sync();
}
void ServerListModel::removeServerAtIndex(int row)
{
const auto stateConfig = KSharedConfig::openStateConfig();
KConfigGroup serverGroup = stateConfig->group(u"Servers"_s);
serverGroup.deleteEntry(data(index(row), UrlRole).toString());
beginRemoveRows(QModelIndex(), row, row);
m_servers.removeAt(row);
endRemoveRows();
stateConfig->sync();
}
QHash<int, QByteArray> ServerListModel::roleNames() const
{
return {
{UrlRole, QByteArrayLiteral("url")},
{IsHomeServerRole, QByteArrayLiteral("isHomeServer")},
{IsAddServerDelegateRole, QByteArrayLiteral("isAddServerDelegate")},
{IsDeletableRole, QByteArrayLiteral("isDeletable")},
};
}
NeoChatConnection *ServerListModel::connection() const
{
return m_connection;
}
void ServerListModel::setConnection(NeoChatConnection *connection)
{
if (m_connection == connection) {
return;
}
m_connection = connection;
Q_EMIT connectionChanged();
initialize();
}
void ServerListModel::initialize()
{
if (m_connection == nullptr) {
return;
}
beginResetModel();
const auto stateConfig = KSharedConfig::openStateConfig();
const KConfigGroup serverGroup = stateConfig->group(u"Servers"_s);
QString domain = m_connection->domain();
// Add the user's homeserver
m_servers.append(Server{
domain,
true,
false,
false,
});
// Add matrix.org
m_servers.append(Server{
u"matrix.org"_s,
false,
false,
false,
});
// Add each of the saved custom servers
for (const auto &i : serverGroup.keyList()) {
m_servers.append(Server{
serverGroup.readEntry(i, QString()),
false,
false,
true,
});
}
// Add add server delegate entry
m_servers.append(Server{
QString(),
false,
true,
false,
});
beginResetModel();
}
#include "moc_serverlistmodel.cpp"

View File

@@ -0,0 +1,116 @@
// SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#pragma once
#include <Quotient/csapi/list_public_rooms.h>
#include <QAbstractListModel>
#include <QPointer>
#include <QQmlEngine>
#include <QUrl>
class NeoChatConnection;
/**
* @class ServerListModel
*
* This class defines the model for visualising a list of matrix servers.
*
* The list of servers is retrieved from the local cache. Any additions are also
* stored locally so that they are retrieved on subsequent instantiations.
*
* The model also automatically adds the local user's home server and matrix.org to
* the model. Finally the model also adds an entry to create a space in the model
* for an "add new server" delegate.
*/
class ServerListModel : public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(NeoChatConnection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
public:
/**
* @brief Define the data required to represent a server.
*/
struct Server {
QString url; /**< Server URL. */
bool isHomeServer; /**< Whether the server is the local user's home server. */
bool isAddServerDelegate; /**< Wether the item is the "add new server" delegate. */
bool isDeletable; /**< Whether the item can be deleted from the model. */
};
/**
* @brief Defines the model roles.
*/
enum EventRoles {
UrlRole = Qt::UserRole + 1, /**< Server URL. */
IsHomeServerRole, /**< Whether the server is the local user's home server. */
IsAddServerDelegateRole, /**< Whether the item is the add new server delegate. */
IsDeletableRole, /**< Whether the item can be deleted from the model. */
};
explicit ServerListModel(QObject *parent = nullptr);
/**
* @brief Get the given role value at the given index.
*
* @sa QAbstractItemModel::data
*/
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
/**
* @brief Number of rows in the model.
*
* @sa QAbstractItemModel::rowCount
*/
[[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
/**
* @brief Returns a mapping from Role enum values to role names.
*
* @sa EventRoles, QAbstractItemModel::roleNames()
*/
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
/**
* @brief Start a check to see if the given URL is a valid matrix server.
*
* This function starts the check but due to the requests being asynchronous
* the caller will need to watch the serverCheckComplete signal for confirmation.
* The server URL should be treated as invalid until the signal is emitted true.
*
* @sa serverCheckComplete()
*/
Q_INVOKABLE void checkServer(const QString &url);
/**
* @brief Add a new server to the model.
*
* The server will also be stored in local cache.
*/
Q_INVOKABLE void addServer(const QString &url);
/**
* @brief Remove the server at the given index.
*
* The server will also be removed from local cache.
*/
Q_INVOKABLE void removeServerAtIndex(int index);
NeoChatConnection *connection() const;
void setConnection(NeoChatConnection *connection);
Q_SIGNALS:
void serverCheckComplete(QString url, bool valid);
void connectionChanged();
private:
QList<Server> m_servers;
QPointer<Quotient::QueryPublicRoomsJob> m_checkServerJob = nullptr;
QPointer<NeoChatConnection> m_connection;
void initialize();
};

View File

@@ -0,0 +1,189 @@
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
// SPDX-License-Identifier: GPL-3.0-only
#include "userdirectorylistmodel.h"
#include <Quotient/room.h>
#include "neochatconnection.h"
using namespace Quotient;
UserDirectoryListModel::UserDirectoryListModel(QObject *parent)
: QAbstractListModel(parent)
{
}
NeoChatConnection *UserDirectoryListModel::connection() const
{
return m_connection;
}
void UserDirectoryListModel::setConnection(NeoChatConnection *connection)
{
if (m_connection == connection) {
return;
}
beginResetModel();
attempted = false;
users.clear();
if (m_connection) {
m_connection->disconnect(this);
}
endResetModel();
m_connection = connection;
Q_EMIT connectionChanged();
if (m_job) {
m_job->abandon();
m_job = nullptr;
Q_EMIT searchingChanged();
}
}
QString UserDirectoryListModel::searchText() const
{
return m_searchText;
}
void UserDirectoryListModel::setSearchText(const QString &value)
{
if (m_searchText == value) {
return;
}
m_searchText = value;
Q_EMIT searchTextChanged();
if (m_job) {
m_job->abandon();
m_job = nullptr;
Q_EMIT searchingChanged();
}
attempted = false;
}
bool UserDirectoryListModel::searching() const
{
return m_job != nullptr;
}
void UserDirectoryListModel::search(int limit)
{
if (limit < 1) {
return;
}
if (m_job) {
qDebug() << "UserDirectoryListModel: Other jobs running, ignore";
return;
}
if (attempted) {
return;
}
m_job = m_connection->callApi<SearchUserDirectoryJob>(m_searchText, limit);
Q_EMIT searchingChanged();
connect(m_job, &BaseJob::finished, this, [this] {
attempted = true;
if (m_job->status() == BaseJob::Success) {
auto users = m_job->results();
this->beginResetModel();
this->users = users;
this->endResetModel();
}
this->m_job = nullptr;
Q_EMIT searchingChanged();
});
}
QVariant UserDirectoryListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
return QVariant();
}
if (index.row() >= users.count()) {
qDebug() << "UserDirectoryListModel, something's wrong: index.row() >= "
"users.count()";
return {};
}
auto user = users.at(index.row());
if (role == DisplayNameRole) {
auto displayName = user.displayName;
if (!displayName.isEmpty()) {
return displayName;
}
displayName = user.userId;
if (!displayName.isEmpty()) {
return displayName;
}
return u"Unknown User"_s;
}
if (role == AvatarRole) {
auto avatarUrl = user.avatarUrl;
if (avatarUrl.isEmpty() || !m_connection) {
return QUrl();
}
return m_connection->makeMediaUrl(avatarUrl);
}
if (role == UserIDRole) {
return user.userId;
}
if (role == DirectChatExistsRole) {
if (!m_connection) {
return false;
};
auto userObj = m_connection->user(user.userId);
auto directChats = m_connection->directChats();
if (userObj && directChats.contains(userObj)) {
auto directChatsForUser = directChats.values(userObj);
if (!directChatsForUser.isEmpty()) {
return true;
}
}
return false;
}
return {};
}
QHash<int, QByteArray> UserDirectoryListModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[DisplayNameRole] = "displayName";
roles[AvatarRole] = "avatarUrl";
roles[UserIDRole] = "userId";
roles[DirectChatExistsRole] = "directChatExists";
return roles;
}
int UserDirectoryListModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0;
}
return users.count();
}
#include "moc_userdirectorylistmodel.cpp"

View File

@@ -0,0 +1,106 @@
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <QAbstractListModel>
#include <QObject>
#include <QQmlEngine>
#include <Quotient/csapi/users.h>
class NeoChatConnection;
/**
* @class UserDirectoryListModel
*
* This class defines the model for visualising the results of a user search.
*
* The model searches for users that have the given keyword in the matrix
* ID or the display name. See
* https://spec.matrix.org/v1.6/client-server-api/#post_matrixclientv3user_directorysearch
* for more info on matrix user searches.
*/
class UserDirectoryListModel : public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
/**
* @brief The current connection that the model is getting users from.
*/
Q_PROPERTY(NeoChatConnection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
/**
* @brief The text to search the public room list for.
*/
Q_PROPERTY(QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged)
/**
* @brief Whether the model is searching.
*/
Q_PROPERTY(bool searching READ searching NOTIFY searchingChanged)
public:
/**
* @brief Defines the model roles.
*/
enum EventRoles {
DisplayNameRole = Qt::DisplayRole, /**< The user's display name. */
AvatarRole, /**< The source URL for the user's avatar. */
UserIDRole, /**< Matrix ID of the user. */
DirectChatExistsRole, /**< Whether there is already a direct chat with the user. */
};
explicit UserDirectoryListModel(QObject *parent = nullptr);
[[nodiscard]] NeoChatConnection *connection() const;
void setConnection(NeoChatConnection *connection);
[[nodiscard]] QString searchText() const;
void setSearchText(const QString &searchText);
[[nodiscard]] bool searching() const;
/**
* @brief Get the given role value at the given index.
*
* @sa QAbstractItemModel::data
*/
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
/**
* @brief Number of rows in the model.
*
* @sa QAbstractItemModel::rowCount
*/
[[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
/**
* @brief Returns a mapping from Role enum values to role names.
*
* @sa EventRoles, QAbstractItemModel::roleNames()
*/
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
/**
* @brief Search the user directory.
*
* @param limit the maximum number of rooms to load.
*/
Q_INVOKABLE void search(int limit = 50);
Q_SIGNALS:
void connectionChanged();
void searchTextChanged();
void searchingChanged();
private:
QPointer<NeoChatConnection> m_connection;
QString m_searchText;
bool attempted = false;
QList<Quotient::SearchUserDirectoryJob::User> users;
Quotient::SearchUserDirectoryJob *m_job = nullptr;
};

View File

@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include "userfiltermodel.h"
#include "models/userlistmodel.h"
bool UserFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
Q_UNUSED(sourceParent);
if (!m_allowEmpty && m_filterText.length() < 1) {
return false;
}
return sourceModel()->data(sourceModel()->index(sourceRow, 0), UserListModel::DisplayNameRole).toString().contains(m_filterText, Qt::CaseInsensitive)
|| sourceModel()->data(sourceModel()->index(sourceRow, 0), UserListModel::UserIdRole).toString().contains(m_filterText, Qt::CaseInsensitive);
}
QString UserFilterModel::filterText() const
{
return m_filterText;
}
void UserFilterModel::setFilterText(const QString &filterText)
{
m_filterText = filterText;
Q_EMIT filterTextChanged();
invalidateFilter();
}
bool UserFilterModel::allowEmpty() const
{
return m_allowEmpty;
}
void UserFilterModel::setAllowEmpty(bool allowEmpty)
{
m_allowEmpty = allowEmpty;
Q_EMIT allowEmptyChanged();
}
#include "moc_userfiltermodel.cpp"

View File

@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#pragma once
#include <QQmlEngine>
#include <QSortFilterProxyModel>
/**
* @class UserFilterModel
*
* This class creates a custom QSortFilterProxyModel for filtering a users by either
* display name or matrix ID. The filter can accept a full matrix id i.e. example:kde.org
* to separate between accounts on different servers with similar names.
*/
class UserFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
QML_ELEMENT
/**
* @brief This property hold the text of the filter.
*
* The text is either a desired display name or matrix id.
*/
Q_PROPERTY(QString filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged)
Q_PROPERTY(bool allowEmpty READ allowEmpty WRITE setAllowEmpty NOTIFY allowEmptyChanged)
public:
/**
* @brief Custom filter function checking boith the display name and matrix ID.
*
* @note The filter cannot be modified and will always use the same filter properties.
*/
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
QString filterText() const;
void setFilterText(const QString &filterText);
bool allowEmpty() const;
void setAllowEmpty(bool allowEmpty);
Q_SIGNALS:
void filterTextChanged();
void allowEmptyChanged();
private:
QString m_filterText;
bool m_allowEmpty = false;
};

344
src/app/neochat.notifyrc Normal file
View File

@@ -0,0 +1,344 @@
[Global]
IconName=org.kde.neochat
Name=NeoChat
Name[ar]=نيوتشات
Name[ast]=NeoChat
Name[az]=NeoChat
Name[ca]=NeoChat
Name[ca@valencia]=NeoChat
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
Name[fr]=NeoChat
Name[gl]=NeoChat
Name[he]=NeoChat
Name[hi]=नियोचैट
Name[hu]=NeoChat
Name[ia]=Neochat
Name[id]=NeoChat
Name[ie]=NeoChat
Name[it]=NeoChat
Name[ka]=NeoChat
Name[ko]=NeoChat
Name[lt]=NeoChat
Name[lv]=NeoChat
Name[nl]=NeoChat
Name[nn]=NeoChat
Name[pa]=ਨਿਓ-ਚੈਟ
Name[pl]=NeoChat
Name[pt]=NeoChat
Name[pt_BR]=NeoChat
Name[ro]=NeoChat
Name[ru]=NeoChat
Name[sa]=नवचैट्
Name[sk]=NeoChat
Name[sl]=NeoChat
Name[sv]=NeoChat
Name[ta]=நியோச்சாட்
Name[tr]=NeoChat
Name[uk]=NeoChat
Name[x-test]=xxNeoChatxx
Name[zh_CN]=NeoChat
Name[zh_TW]=NeoChat
DesktopEntry=org.kde.neochat
Comment=A client for matrix, the decentralized communication protocol
Comment[ar]=عميل لماتركس، ميفاق الاتصال اللامركزي
Comment[az]=Matrix üçün müştəri, mərkəzləşməmiş kommunikasiya protokolu
Comment[ca]=Un client per a Matrix, el protocol de comunicacions descentralitzat
Comment[ca@valencia]=Un client per a Matrix, el protocol de comunicacions descentralitzat
Comment[cs]=Klient pro decentralizovaný komunikační protokol matrix
Comment[de]=Ein Programm für Matrix, das dezentrale Kommunikationsprotokoll
Comment[el]=Ένας πελάτης για το Matrix, το αποκεντρωμένο πρωτόκολλο επικοινωνίας
Comment[en_GB]=A client for matrix, the decentralised communication protocol
Comment[eo]=Kliento por matrix, la malcentra komunikprotokolo
Comment[es]=Un cliente para Matrix, el protocolo de comunicaciones descentralizado
Comment[eu]=Matrix, deszentralizatutako komunikazio protokolorako, bezero bat
Comment[fi]=Hajautetun Matrix-viestintäyhteyskäytännön asiakasohjelma
Comment[fr]=Un client pour « Matrix », le protocole décentralisé de communications.
Comment[gl]=Un cliente para Matrix, o protocolo de comunicación descentralizada.
Comment[he]=לקוח ל־matrix, פרוטוקול התקשורת המבוזר
Comment[hi]=मैट्रिक्स के लिए एक क्लाइंट, विकेन्द्रीकृत संचार प्रोटोकॉल
Comment[hu]=Kliens a matrixhoz, a decentralizált kommunikációs protokollhoz
Comment[ia]=Un cliente per Matrix, le protocollo de communication decentralisate
Comment[id]=Sebuah klien untuk matrix, protokol komunikasi terdecentralisasi
Comment[ie]=Un cliente de Matrix, li protocol de communication decentralisat.
Comment[it]=Un client per matrix, il protocollo di comunicazione decentralizzato
Comment[ka]=კლიენტი Matrix-სთვის, დეცენტრალიზებული კომუნიკაციის პროტოკოლისთვის
Comment[ko]=Matrix, 분산 대화 프로토콜 클라이언트
Comment[lt]=Matrix decentralizuoto bendravimo protokolo kliento programa
Comment[lv]=Klients „Matrix“ protokolam — decentralizētam komunikācijas protokolam
Comment[nl]=Een client voor matrix, het gedecentraliseerde communicatieprotocol
Comment[nn]=Ein klient for Matrix  protokollen for desentralisert kommunikasjon
Comment[pa]=ਮੈਟਰਿਕਸ, ਸਰਬ-ਸਾਂਝੇ ਸੰਚਾਰ ਪਰੋਟੋਕਾਲ, ਲਈ ਕਲਾਈਂਟ ਹੈ
Comment[pl]=Program do obsługi matriksa, rozproszonego protokołu porozumiewania się
Comment[pt]=Um cliente para o Matrix, o protocolo descentralizado de comunicações
Comment[pt_BR]=Um cliente para o Matrix, o protocolo de comunicação decentralizado
Comment[ro]=Client pentru Matrix, protocolul de comunicare descentralizată
Comment[ru]=Клиент для Matrix — децентрализованного коммуникационного протокола
Comment[sa]=मैट्रिक्सस्य कृते एकः क्लायन्ट्, विकेन्द्रीकृतसञ्चारप्रोटोकॉलः
Comment[sk]=Klient pre matrix, decentralizovaný komunikačný protokol
Comment[sl]=Odjemalec za decentralizirani komunikacijski protokol matrix
Comment[sv]=En klient för matrix, det decentraliserade kommunikationsprotokollet
Comment[ta]=மையமில்லா தகவல் பரிமாற்ற நெறிமுறையான மேட்ரிக்ஸுக்கான செயலி
Comment[tr]=Merkezi olmayan iletişim protokolü Matrix için bir istemci
Comment[uk]=Клієнт matrix, децентралізованого протоколу обміну даними
Comment[x-test]=xxA client for matrix, the decentralized communication protocolxx
Comment[zh_CN]=分布式通讯协议 Matrix 的客户端
Comment[zh_TW]=去中心化通訊協定 Matrix 的用戶端
[Event/message]
Name=New message
Name[ar]=رسالة جديدة
Name[az]=Yeni ismarıc
Name[ca]=Missatge nou
Name[ca@valencia]=Missatge nou
Name[cs]=Nová zpráva
Name[de]=Neue Nachricht
Name[el]=Νέο μήνυμα
Name[en_GB]=New message
Name[eo]=Nova mesaĝo
Name[es]=Nuevo mensaje
Name[eu]=Mezu berria
Name[fi]=Uusi viesti
Name[fr]=Nouveau message
Name[gl]=Nova mensaxe
Name[he]=הודעה חדשה
Name[hi]=नया सन्देश
Name[hu]=Új üzenet
Name[ia]=Nove message
Name[id]=Pesan baru
Name[ie]=Nov missage
Name[it]=Nuovo messaggio
Name[ka]=ახალი შეტყობინება
Name[ko]=새 메시지
Name[lt]=Nauja žinutė
Name[lv]=Jauns ziņojums
Name[nl]=Nieuw bericht
Name[nn]=Ny melding
Name[pa]=ਨਵਾਂ ਸੁਨੇਹਾ
Name[pl]=Nowa wiadomość
Name[pt]=Nova mensagem
Name[pt_BR]=Nova mensagem
Name[ro]=Mesaj nou
Name[ru]=Новое сообщение
Name[sa]=नूतनः सन्देशः
Name[sk]=Nová správa
Name[sl]=Novo sporočilo
Name[sv]=Nytt meddelande
Name[ta]=புதிய செய்தி
Name[tr]=Yeni İleti
Name[uk]=Нове повідомлення
Name[x-test]=xxNew messagexx
Name[zh_CN]=新消息
Name[zh_TW]=新訊息
Comment=There is a new message
Comment[ar]=توجد رسالة جديدة
Comment[az]=Yeni ismarıc var
Comment[ca]=Hi ha un missatge nou
Comment[ca@valencia]=Hi ha un missatge nou
Comment[de]=Es gibt eine neue Nachricht
Comment[el]=Υπάρχει ένα νέο μήνυμα
Comment[en_GB]=There is a new message
Comment[eo]=Estas nova mesaĝo
Comment[es]=Hay un mensaje nuevo
Comment[eu]=Mezu berri bat dago
Comment[fi]=Saapui uusi viesti
Comment[fr]=Il y a un nouveau message
Comment[gl]=Hai unha nova mensaxe.
Comment[he]=יש הודעה חדשה
Comment[hi]=एक नया संदेश है
Comment[hu]=Új üzenet érkezett
Comment[ia]=Il ha un nove message
Comment[id]=Ada pesan baru
Comment[ie]=Vu have un nov missage
Comment[it]=È presente un nuovo messaggio
Comment[ka]=გაქვთ ახალი შეტყობინება
Comment[ko]=새 메시지가 있음
Comment[lt]=Yra nauja žinutė
Comment[lv]=Ir pienācis jauns ziņojums
Comment[nl]=Er is een nieuw bericht
Comment[nn]=Du har ei ny melding
Comment[pa]=ਨਵਾਂ ਸੁਨੇਹਾ ਹੈ
Comment[pl]=Dostępna jest nowa wiadomość
Comment[pt]=Tem uma mensagem nova
Comment[pt_BR]=Existe uma nova mensagem
Comment[ro]=Este un mesaj nou
Comment[ru]=Доступно новое сообщение
Comment[sa]=तत्र नूतनः सन्देशः अस्ति
Comment[sk]=Je nová správa
Comment[sl]=Prišlo je novo sporočilo
Comment[sv]=Det finns ett nytt meddelande
Comment[ta]=ஒரு புதிய செய்தி உள்ளது
Comment[tr]=Yeni bir ileti var
Comment[uk]=Надійшло нове повідомлення
Comment[x-test]=xxThere is a new messagexx
Comment[zh_CN]=有新消息
Comment[zh_TW]=有新的訊息
Action=Popup
[Event/invite]
Name=New Invitation
Name[ar]=دعوة جديدة
Name[az]=Yeni dəvət
Name[ca]=Invitació nova
Name[ca@valencia]=Invitació nova
Name[cs]=Nová pozvánka
Name[de]=Neue Einladung
Name[el]=Νέα πρόσκληση
Name[en_GB]=New Invitation
Name[eo]=Nove Invito
Name[es]=Nueva invitación
Name[eu]=Gonbidapen berria
Name[fi]=Uusi kutsu
Name[fr]=Nouvelle invitation
Name[gl]=Novo convite
Name[he]=הזמנה חדשה
Name[hi]=नया आमंत्रण
Name[hu]=Új meghívó
Name[ia]=Nove invitation
Name[id]=Undangan Baru
Name[ie]=Nov invitation
Name[it]=Nuovo invito
Name[ka]=ახალი მოსაწვევი
Name[ko]=새 초대장
Name[lt]=Naujas pakvietimas
Name[lv]=Jauns uzaicinājums
Name[nl]=Nieuwe uitnodiging
Name[nn]=Ny invitasjon
Name[pa]=ਨਵਾਂ ਸੱਦਾ
Name[pl]=Nowe zaproszenie
Name[pt]=Novo Convite
Name[pt_BR]=Novo convite
Name[ru]=Новое приглашение
Name[sa]=नवीन आमन्त्रणम्
Name[sl]=Novo povabilo
Name[sv]=Ny inbjudan
Name[ta]=புதிய அழைப்பிதழ்
Name[tr]=Yeni Davet
Name[uk]=Нове запрошення
Name[x-test]=xxNew Invitationxx
Name[zh_CN]=新邀请
Name[zh_TW]=新邀請
Comment=There is a new invitation to a room
Comment[ar]=توجد دعوة جديدة
Comment[az]=Otağa bir yeni dəvət var
Comment[ca]=Hi ha una invitació nova a una sala
Comment[ca@valencia]=Hi ha una invitació nova a una sala
Comment[cs]=Máte novou pozvánku do místnosti
Comment[de]=Es gibt eine neue Einladung zu einem Raum
Comment[el]=Υπάρχει μια νέα πρόσκληση σε μια αίθουσα
Comment[en_GB]=There is a new invitation to a room
Comment[eo]=Estas nova invito al ĉambro
Comment[es]=Hay una nueva invitación a una sala
Comment[eu]=Gela baterako gonbidapen berri bat dago
Comment[fi]=Uusi kutsu huoneeseen
Comment[fr]=Il y a une nouvelle invitation dans un salon.
Comment[gl]=Tes un novo convite para unha sala.
Comment[he]=יש הזמנה חדשה לחדר
Comment[hi]=एक कमरे में नया आमंत्रण आया है
Comment[hu]=Új meghívó érkezett egy szobába
Comment[ia]=Il ha un nove invitation a un sala
Comment[id]=Ada undangan baru ke sebuah ruangan
Comment[ie]=Vu have un nov invitation a un chambre
Comment[it]=È presente un nuovo invito a una stanza
Comment[ka]=გაქვთ ახალი ოთახის მოსაწვევი
Comment[ko]=새로운 대화방 초대장을 받음
Comment[lt]=Yra naujas pakvietimas į kambarį
Comment[lv]=Istabā ir jauns uzaicinājums
Comment[nl]=Er is een nieuwe uitnodiging naar een room
Comment[nn]=Du har ein ny invitasjon til eit rom
Comment[pa]=ਰੂਮ ਲਈ ਨਵਾਂ ਸੱਦਾ ਹੈ
Comment[pl]=Dostępna jest nowe zaproszenie do pokoju
Comment[pt]=Existe um novo convite para uma sala
Comment[pt_BR]=Existe um novo convite para uma sala
Comment[ru]=Доступно новое приглашение в комнату
Comment[sa]=कक्षस्य नूतनं निमन्त्रणम् अस्ति
Comment[sl]=Tam je novo povabilo v sobo
Comment[sv]=Det finns en ny inbjudan till ett rum
Comment[ta]=ஓர் அரங்கிற்கான புதிய அழைப்பிதழ் உள்ளது
Comment[tr]=Bir odaya yeni bir davetiye var
Comment[uk]=У кімнаті нове запрошення
Comment[x-test]=xxThere is a new invitation to a roomxx
Comment[zh_CN]=有新的聊天室邀请
Comment[zh_TW]=有新的加入聊天室邀請
Action=Popup
[Event/Share]
Name=Share
Name[ar]=شارك
Name[ca]=Compartició
Name[ca@valencia]=Compartiu
Name[cs]=Sdílet
Name[de]=Teilen
Name[el]=Κοινοποίηση
Name[en_GB]=Share
Name[eo]=Kundividi
Name[es]=Compartir
Name[eu]=Partekatu
Name[fi]=Jaa
Name[fr]=Partager
Name[gl]=Compartir
Name[he]=שיתוף
Name[hi]=शेयर करना
Name[hu]=Megosztás
Name[ia]=Comparti
Name[it]=Condivisione
Name[ka]=გაზიარება
Name[ko]=공유
Name[lv]=Kopīgot
Name[nl]=Gedeelde
Name[nn]=Del
Name[pl]=Udostępnij
Name[pt_BR]=Compartilhar
Name[ru]=Публикация
Name[sa]=संविभागः
Name[sl]=Deli
Name[sv]=Dela
Name[ta]=பகிர்
Name[tr]=Paylaş
Name[uk]=Оприлюднення
Name[x-test]=xxSharexx
Name[zh_CN]=分享
Name[zh_TW]=分享
Comment=The result of sharing a piece of content
Comment[ar]=نتيجة مشاركة محتوى
Comment[ca]=El resultat de compartir una peça de contingut
Comment[ca@valencia]=El resultat de compartir una peça de contingut
Comment[de]=Das Ergebnis nach dem Teilen eines Teils des Inhalts
Comment[el]=Το αποτέλεσμα του διαμοιρασμού ενός περιεχομένου
Comment[en_GB]=The result of sharing a piece of content
Comment[eo]=La rezulto el kundividado de enhavero
Comment[es]=El resultado de compartir una parte de contenido
Comment[eu]=Eduki pieza bat partekatzearen emaitza
Comment[fi]=Tulos yhden sisältöosasen jakamisesta
Comment[fr]=Le résultat du partage d'une partie de contenu.
Comment[gl]=O resultado de compartir un fragmento de contido.
Comment[he]=תוצאת שיתוף פיסת תוכן
Comment[hi]=सामग्री का एक अंश साझा करने का परिणाम
Comment[hu]=Tartalom megosztásának eredménye
Comment[ia]=Le exito de compartir un pecietta de contento
Comment[it]=Il risultato della condivisione di un contenuto
Comment[ka]=შემცველობის ნაწილის გაზიარების შედეგი
Comment[ko]=콘텐츠 공유 결과
Comment[lv]=Satura kopīgošanas rezultāts
Comment[nl]=Het resultaat van het delen van een stukje inhoud
Comment[nn]=Resultatet av deling av innhald
Comment[pl]=Wynik udostępniania kawałka treści
Comment[pt_BR]=O resultado de compartilhar um conteúdo
Comment[ru]=Результат публикации данных
Comment[sa]=सामग्रीखण्डस्य साझाकरणस्य परिणामः
Comment[sl]=Rezultat deljenega kosa vsebine
Comment[sv]=Resultatet av att dela innehåll
Comment[ta]=எதையோ பகிர்ந்த‍தன் விளைவு
Comment[tr]=Bir parça içerik paylaşımının sonucu
Comment[uk]=Результат оприлюднення даних
Comment[x-test]=xxThe result of sharing a piece of contentxx
Comment[zh_CN]=分享一个内容得到的结果
Comment[zh_TW]=分享一份內容之後的結果
Action=Popup

220
src/app/neochatconfig.kcfg Normal file
View File

@@ -0,0 +1,220 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="neochatrc" />
<group name="General">
<entry name="AllRoomsInHome" type="bool">
<label>Show all rooms in the home tab</label>
<default>false</default>
</entry>
<entry name="CollapsedSections" type="IntList">
<label>Collapsed sections in the room list</label>
</entry>
<entry name="OpenRoom" type="String">
<label>Latest opened room</label>
</entry>
<entry name="Blur" type="bool">
<label>Make NeoChat blurry</label>
<default>false</default>
</entry>
<entry name="Transparency" type="Double">
<label>Background transparency value</label>
<default>0.3</default>
</entry>
<entry name="AllowQuickEdit" type="bool">
<label>Use s/text/replacement syntax to edit your last message.</label>
<default>false</default>
</entry>
<entry name="SendMessageWith" type="Enum">
<label>Key combination to send a message</label>
<choices>
<choice name="Enter">
<label>Enter</label>
</choice>
<choice name="CtrlEnter">
<label>Ctrl+Enter</label>
</choice>
<default>Enter</default>
</choices>
</entry>
<entry name="ShowLocalMessagesOnRight" type="bool">
<label>"Show your messages on the right</label>
<default>true</default>
</entry>
<entry name="RoomDrawerWidth" type="int">
<default>-1</default>
</entry>
<entry name="TypingNotifications" type="bool">
<default>true</default>
</entry>
<entry name="AutoRoomInfoDrawer" type="bool">
<label>Automatic Hide/Unhide Room Information</label>
<default>true</default>
</entry>
<entry name="DeveloperTools" type="bool">
<label>Enable developer tools</label>
<default>false</default>
</entry>
<entry name="LastSaveDirectory" type="String">
<label>Directory last used for saving a file</label>
</entry>
<entry name="KeywordPushRuleDefault" type="int">
<label>The default setting for a new keyword push rule.</label>
<default>4</default>
</entry>
</group>
<group name="Timeline">
<entry name="ShowAvatarInTimeline" type="bool">
<label>Show avatar in the timeline</label>
<default>true</default>
</entry>
<entry name="CompactLayout" type="bool">
<label>Use a compact chat layout</label>
<default>false</default>
</entry>
<entry name="CompactRoomList" type="bool">
<label>Use a compact room list layout</label>
<default>false</default>
</entry>
<entry name="ShowStateEvent" type="bool">
<label>Show state events in the timeline</label>
<default>true</default>
</entry>
<entry name="ShowLeaveJoinEvent" type="bool">
<label>Show leave and join events in the timeline</label>
<default>true</default>
</entry>
<entry name="ShowRename" type="bool">
<label>Show rename events in the timeline</label>
<default>false</default>
</entry>
<entry name="ShowAvatarUpdate" type="bool">
<label>Show avatar update events in the timeline</label>
<default>false</default>
</entry>
<entry name="ShowDeletedMessages" type="bool">
<label>Show deleted messages in the timeline</label>
<default>false</default>
</entry>
<entry name="HideImages" type="bool">
<label>Hide images in the timeline</label>
<default>false</default>
</entry>
<entry name="ShowLinkPreview" type="bool">
<label>Show preview of the links in the chat messages</label>
<default>true</default>
</entry>
<entry name="SystemTray" type="bool">
<label>Close NeoChat to system tray</label>
<default>false</default>
</entry>
<entry name="MinimizeToSystemTrayOnStartup" type="bool">
<label>Minimize to system tray on startup</label>
<default>false</default>
</entry>
<entry name="MediaMaxWidth" type="int">
<label>The maximum width any media item in the timeline can be.</label>
<default>540</default>
</entry>
<entry name="MediaMaxHeight" type="int">
<label>The maximum height any media item in the timeline can be.</label>
<default>540</default>
</entry>
</group>
<group name="RoomDrawer">
<entry name="ShowAvatarInRoomDrawer" type="bool">
<label>Show avatar in the room drawer</label>
<default>true</default>
</entry>
<entry name="Collapsed" type="bool">
<label>Save the collapsed state of the room list</label>
<default>false</default>
</entry>
<entry name="SortOrder" type="Enum">
<label>The sort order for the rooms in the list.</label>
<choices name="::RoomSortOrder::Order">
</choices>
</entry>
<entry name="CustomSortOrder" type="IntList">
<label>The list of parameter in order to use for custom sorting</label>
<default></default>
</entry>
</group>
<group name="NetworkProxy">
<entry name="ProxyType" type="Enum">
<label>The type of proxy used by the application.</label>
<choices>
<choice name="System">
<label>System Default</label>
</choice>
<choice name="HTTP">
<label>HTTP</label>
</choice>
<choice name="Socks5">
<label>Socks5</label>
</choice>
<choice name="NoProxy">
<label>NoProxy</label>
</choice>
<default>System</default>
</choices>
</entry>
<entry name="ProxyHost" type="String">
<label>IP or hostname of the proxy</label>
<default>127.0.0.1</default>
</entry>
<entry name="ProxyPort" type="int">
<label>The port number of the proxy</label>
<default>1080</default>
</entry>
<entry name="ProxyUser" type="String">
<label>The user of the proxy</label>
<default></default>
</entry>
<entry name="ProxyPassword" type="Password">
<label>The password of the proxy</label>
<default></default>
</entry>
</group>
<group name="Debug">
<entry name="ShowAllEvents" type="bool">
<label>Don't hide any events in the timeline</label>
<default>false</default>
</entry>
<entry name="AlwaysVerifyDevice" type="bool">
<label>Always allow device verification</label>
<default>false</default>
</entry>
<entry name="WindowTitleFocus" type="bool">
<label>Show the current focus item in the window title</label>
<default>false</default>
</entry>
</group>
<group name="FeatureFlags">
<entry name="Threads" type="bool">
<label>Enable threads</label>
<default>false</default>
</entry>
<entry name="SecretBackup" type="bool">
<label>Enable secret backup</label>
<default>false</default>
</entry>
<entry name="Phone3PId" type="bool">
<label>Enable add phone numbers as 3PIDs</label>
<default>false</default>
</entry>
</group>
<group name="Security">
<entry name="RejectUnknownInvites" type="bool">
<label>Reject unknown invites</label>
<default>false</default>
</entry>
<entry name="PreferUsingEncryption" type="bool">
<label>Prefer encrypting chats</label>
<default>true</default>
</entry>
</group>
</kcfg>

View File

@@ -0,0 +1,450 @@
// SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "notificationsmanager.h"
#include <memory>
#include <QGuiApplication>
#include <KLocalizedString>
#include <KNotification>
#include <KNotificationPermission>
#include <KNotificationReplyAction>
#include <QPainter>
#include <Quotient/accountregistry.h>
#include <Quotient/csapi/pushrules.h>
#include <Quotient/events/roommemberevent.h>
#include <Quotient/user.h>
#ifdef HAVE_KIO
#include <KIO/ApplicationLauncherJob>
#endif
#include "controller.h"
#include "jobs/neochatgetcommonroomsjob.h"
#include "neochatconfig.h"
#include "neochatconnection.h"
#include "neochatroom.h"
#include "roommanager.h"
#include "texthandler.h"
#include "windowcontroller.h"
using namespace Quotient;
NotificationsManager::NotificationsManager(QObject *parent)
: QObject(parent)
{
}
void NotificationsManager::handleNotifications(QPointer<NeoChatConnection> connection)
{
if (KNotificationPermission::checkPermission() == Qt::PermissionStatus::Granted) {
startNotificationJob(connection);
} else if (!permissionAsked) {
KNotificationPermission::requestPermission(this, [this, connection](Qt::PermissionStatus result) {
if (result == Qt::PermissionStatus::Granted) {
startNotificationJob(connection);
} else {
permissionAsked = true;
}
});
}
}
void NotificationsManager::startNotificationJob(QPointer<NeoChatConnection> connection)
{
if (connection == nullptr) {
return;
}
if (!m_connActiveJob.contains(connection->user()->id())) {
auto job = connection->callApi<GetNotificationsJob>();
m_connActiveJob.append(connection->user()->id());
connect(job, &BaseJob::success, this, [this, job, connection]() {
m_connActiveJob.removeAll(connection->user()->id());
processNotificationJob(connection, job, !m_oldNotifications.contains(connection->user()->id()));
});
}
}
void NotificationsManager::processNotificationJob(QPointer<NeoChatConnection> connection, Quotient::GetNotificationsJob *job, bool initialization)
{
if (!job || !connection || !connection->isLoggedIn()) {
return;
}
const auto connectionId = connection->user()->id();
const auto notifications = job->jsonData()["notifications"_L1].toArray();
if (initialization) {
for (const auto &notification : notifications) {
if (!m_initialTimestamp.contains(connectionId)) {
m_initialTimestamp[connectionId] = notification["ts"_L1].toVariant().toLongLong();
} else {
qint64 timestamp = notification["ts"_L1].toVariant().toLongLong();
if (timestamp > m_initialTimestamp[connectionId]) {
m_initialTimestamp[connectionId] = timestamp;
}
}
auto connectionNotifications = m_oldNotifications.value(connectionId);
connectionNotifications += notification["event"_L1]["event_id"_L1].toString();
m_oldNotifications[connectionId] = connectionNotifications;
}
return;
}
QMap<QString, std::pair<qint64, QJsonObject>> notificationsToPost;
for (const auto &n : notifications) {
const auto notification = n.toObject();
if (notification["read"_L1].toBool()) {
continue;
}
auto connectionNotifications = m_oldNotifications.value(connectionId);
if (connectionNotifications.contains(notification["event"_L1]["event_id"_L1].toString())) {
continue;
}
connectionNotifications += notification["event"_L1]["event_id"_L1].toString();
m_oldNotifications[connectionId] = connectionNotifications;
if (!shouldPostNotification(connection, n)) {
continue;
}
const auto &roomId = notification["room_id"_L1].toString();
if (!notificationsToPost.contains(roomId) || notificationsToPost[roomId].first < notification["ts"_L1].toVariant().toLongLong()) {
notificationsToPost[roomId] = {notification["ts"_L1].toVariant().toLongLong(), notification};
}
}
for (const auto &[roomId, pair] : notificationsToPost.asKeyValueRange()) {
const auto &notification = pair.second;
const auto room = connection->room(roomId);
if (!room) {
continue;
}
auto sender = room->member(notification["event"_L1]["sender"_L1].toString());
if (room->joinState() == JoinState::Invite) {
postInviteNotification(qobject_cast<NeoChatRoom *>(room));
continue;
}
QString body;
if (notification["event"_L1]["type"_L1].toString() == "org.matrix.msc3381.poll.start"_L1) {
body = notification["event"_L1]["content"_L1]["org.matrix.msc3381.poll.start"_L1]["question"_L1]["body"_L1].toString();
} else if (notification["event"_L1]["type"_L1] == "m.room.encrypted"_L1) {
const auto decrypted = connection->decryptNotification(notification);
body = decrypted["content"_L1]["body"_L1].toString();
if (body.isEmpty()) {
body = i18n("Encrypted Message");
}
} else {
body = notification["event"_L1]["content"_L1]["body"_L1].toString();
}
QImage avatar_image;
if (!sender.avatarUrl().isEmpty()) {
avatar_image = room->member(sender.id()).avatar(128, 128, {});
} else {
avatar_image = room->avatar(128);
}
postNotification(dynamic_cast<NeoChatRoom *>(room),
sender.displayName(),
body,
avatar_image,
notification["event"_L1].toObject()["event_id"_L1].toString(),
true,
pair.first);
}
}
bool NotificationsManager::shouldPostNotification(QPointer<NeoChatConnection> connection, const QJsonValue &notification)
{
if (connection == nullptr || !connection->isLoggedIn()) {
return false;
}
auto room = connection->room(notification["room_id"_L1].toString());
if (room == nullptr) {
return false;
}
// If the room is the current room and the application is active the notification
// should not be shown.
// This is setup so that if the application is inactive the notification will
// always be posted, even if the room is the current room.
bool isCurrentRoom = RoomManager::instance().currentRoom() && room->id() == RoomManager::instance().currentRoom()->id();
if (isCurrentRoom && QGuiApplication::applicationState() == Qt::ApplicationActive) {
return false;
}
// If the notification timestamp is earlier than the initial timestamp assume
// the notification is old and shouldn't be posted.
qint64 timestamp = notification["ts"_L1].toDouble();
if (timestamp < m_initialTimestamp[connection->user()->id()]) {
return false;
}
if (m_notifications.contains(room->id()) && m_notifications[room->id()].first > timestamp) {
return false;
}
return true;
}
void NotificationsManager::postNotification(NeoChatRoom *room,
const QString &sender,
const QString &text,
const QImage &icon,
const QString &replyEventId,
bool canReply,
qint64 timestamp)
{
const QString roomId = room->id();
if (auto notification = m_notifications.value(roomId).second) {
notification->close();
}
auto notification = new KNotification(u"message"_s);
m_notifications.insert(roomId, {timestamp, notification});
connect(notification, &KNotification::closed, this, [this, roomId, notification] {
if (m_notifications[roomId].second == notification) {
m_notifications.remove(roomId);
}
});
QString entry;
if (sender == room->displayName()) {
notification->setTitle(sender);
entry = text.toHtmlEscaped();
} else {
notification->setTitle(room->displayName());
entry = i18n("%1: %2", sender, text.toHtmlEscaped());
}
notification->setText(entry);
notification->setPixmap(createNotificationImage(icon, room));
auto defaultAction = notification->addDefaultAction(i18n("Open NeoChat in this room"));
connect(defaultAction, &KNotificationAction::activated, this, [notification, room]() {
WindowController::instance().showAndRaiseWindow(notification->xdgActivationToken());
if (!room) {
return;
}
auto connection = dynamic_cast<NeoChatConnection *>(Controller::instance().accounts()->get(room->localMember().id()));
Controller::instance().setActiveConnection(connection);
RoomManager::instance().setConnection(connection);
RoomManager::instance().resolveResource(room->id());
});
if (canReply) {
std::unique_ptr<KNotificationReplyAction> replyAction(new KNotificationReplyAction(i18n("Reply")));
replyAction->setPlaceholderText(i18n("Reply…"));
connect(replyAction.get(), &KNotificationReplyAction::replied, this, [room, replyEventId](const QString &text) {
TextHandler textHandler;
textHandler.setData(text);
auto content = std::make_unique<Quotient::EventContent::TextContent>(textHandler.handleSendText(), u"text/html"_s);
EventRelation relatesTo = EventRelation::replyTo(replyEventId);
room->post<Quotient::RoomMessageEvent>(text, MessageEventType::Text, std::move(content), relatesTo);
});
notification->setReplyAction(std::move(replyAction));
}
notification->setHint(u"x-kde-origin-name"_s, room->localMember().id());
notification->sendEvent();
}
void NotificationsManager::postInviteNotification(NeoChatRoom *rawRoom)
{
QPointer room(rawRoom);
const auto roomMemberEvent = room->currentState().get<RoomMemberEvent>(room->localMember().id());
if (roomMemberEvent == nullptr) {
return;
}
if (NeoChatConfig::rejectUnknownInvites()) {
auto job = room->connection()->callApi<NeochatGetCommonRoomsJob>(roomMemberEvent->senderId());
connect(job, &BaseJob::result, this, [this, job, room] {
QJsonObject replyData = job->jsonData();
if (replyData.contains(u"joined"_s)) {
const bool inAnyOfOurRooms = !replyData["joined"_L1].toArray().isEmpty();
if (inAnyOfOurRooms) {
doPostInviteNotification(room);
} else {
room->leaveRoom();
}
}
});
} else {
doPostInviteNotification(room);
}
}
void NotificationsManager::doPostInviteNotification(QPointer<NeoChatRoom> room)
{
const auto roomMemberEvent = room->currentState().get<RoomMemberEvent>(room->localMember().id());
if (roomMemberEvent == nullptr) {
return;
}
const auto sender = room->member(roomMemberEvent->senderId());
QImage avatar_image;
if (roomMemberEvent && !room->member(roomMemberEvent->senderId()).avatarUrl().isEmpty()) {
avatar_image = room->member(roomMemberEvent->senderId()).avatar(128, 128, {});
} else {
qWarning() << "using this room's avatar";
avatar_image = room->avatar(128);
}
KNotification *notification = new KNotification(u"invite"_s);
notification->setText(i18n("%1 invited you to a room", sender.htmlSafeDisplayName()));
notification->setTitle(room->displayName());
notification->setPixmap(createNotificationImage(avatar_image, nullptr));
auto defaultAction = notification->addDefaultAction(i18n("Open this invitation in NeoChat"));
connect(defaultAction, &KNotificationAction::activated, this, [notification, room]() {
if (!room) {
return;
}
WindowController::instance().showAndRaiseWindow(notification->xdgActivationToken());
notification->close();
RoomManager::instance().resolveResource(room->id());
});
const auto acceptAction = notification->addAction(i18nc("@action:button The thing being accepted is an invitation to chat", "Accept"));
const auto rejectAction = notification->addAction(i18nc("@action:button The thing being rejected is an invitation to chat", "Reject"));
const auto rejectAndIgnoreAction =
notification->addAction(i18nc("@action:button The thing being rejected is an invitation to chat", "Reject and Ignore User"));
connect(acceptAction, &KNotificationAction::activated, this, [room, notification]() {
if (!room) {
return;
}
room->acceptInvitation();
notification->close();
});
connect(rejectAction, &KNotificationAction::activated, this, [room, notification]() {
if (!room) {
return;
}
RoomManager::instance().leaveRoom(room);
notification->close();
});
connect(rejectAndIgnoreAction, &KNotificationAction::activated, this, [room, notification]() {
if (!room) {
return;
}
RoomManager::instance().leaveRoom(room);
room->connection()->addToIgnoredUsers(room->invitingUserId());
notification->close();
});
connect(notification, &KNotification::closed, this, [this, room]() {
if (!room) {
return;
}
m_invitations.remove(room->id());
});
notification->setHint(u"x-kde-origin-name"_s, room->localMember().id());
notification->sendEvent();
}
void NotificationsManager::clearInvitationNotification(const QString &roomId)
{
if (m_invitations.contains(roomId)) {
m_invitations[roomId]->close();
}
}
void NotificationsManager::postPushNotification(const QByteArray &message)
{
const auto json = QJsonDocument::fromJson(message).object();
const auto type = json["notification"_L1]["type"_L1].toString();
// the only two types of push notifications we support right now
if (type == u"m.room.message"_s || type == u"m.room.encrypted"_s) {
auto notification = new KNotification("message"_L1);
const auto sender = json["notification"_L1]["sender_display_name"_L1].toString();
const auto roomName = json["notification"_L1]["room_name"_L1].toString();
const auto roomId = json["notification"_L1]["room_id"_L1].toString();
if (roomName.isEmpty() || sender == roomName) {
notification->setTitle(sender);
} else {
notification->setTitle(i18n("%1 (%2)", sender, roomName));
}
if (type == u"m.room.message"_s) {
const auto text = json["notification"_L1]["content"_L1]["body"_L1].toString();
notification->setText(text.toHtmlEscaped());
} else if (type == u"m.room.encrypted"_s) {
notification->setText(i18n("Encrypted Message"));
}
#ifdef HAVE_KIO
auto openAction = notification->addAction(i18n("Open NeoChat"));
connect(openAction, &KNotificationAction::activated, this, [=]() {
QString properId = roomId;
properId = properId.replace(u"#"_s, QString());
properId = properId.replace(u"!"_s, QString());
auto *job = new KIO::ApplicationLauncherJob(KService::serviceByDesktopName(u"org.kde.neochat"_s));
job->setUrls({QUrl::fromUserInput(u"matrix:r/%1"_s.arg(properId))});
job->start();
});
#endif
connect(notification, &KNotification::closed, qGuiApp, &QGuiApplication::quit);
notification->sendEvent();
m_notifications.insert(roomId, {json["ts"_L1].toVariant().toLongLong(), notification});
} else {
qWarning() << "Skipping unsupported push notification" << type;
}
}
QPixmap NotificationsManager::createNotificationImage(const QImage &icon, NeoChatRoom *room)
{
// Handle avatars that are lopsided in one dimension
const int biggestDimension = std::max(icon.width(), icon.height());
const QRect imageRect{0, 0, biggestDimension, biggestDimension};
QImage roundedImage(imageRect.size(), QImage::Format_ARGB32);
roundedImage.fill(Qt::transparent);
QPainter painter(&roundedImage);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.setPen(Qt::NoPen);
// Fill background for transparent avatars
painter.setBrush(Qt::white);
painter.drawRoundedRect(imageRect, imageRect.width(), imageRect.height());
QBrush brush(icon.scaledToHeight(biggestDimension));
painter.setBrush(brush);
painter.drawRoundedRect(imageRect, imageRect.width(), imageRect.height());
if (room != nullptr) {
const QImage roomAvatar = room->avatar(imageRect.width(), imageRect.height());
if (icon != roomAvatar) {
const QRect lowerQuarter{imageRect.center(), imageRect.size() / 2};
painter.setBrush(Qt::white);
painter.drawRoundedRect(lowerQuarter, lowerQuarter.width(), lowerQuarter.height());
painter.setBrush(roomAvatar.scaled(lowerQuarter.size()));
painter.drawRoundedRect(lowerQuarter, lowerQuarter.width(), lowerQuarter.height());
}
}
return QPixmap::fromImage(roundedImage);
}
#include "moc_notificationsmanager.cpp"

View File

@@ -0,0 +1,89 @@
// SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QImage>
#include <QJsonObject>
#include <QMap>
#include <QObject>
#include <QPointer>
#include <QQmlEngine>
#include <QString>
#include <Quotient/csapi/notifications.h>
#include <Quotient/jobs/basejob.h>
class NeoChatConnection;
class KNotification;
class NeoChatRoom;
/**
* @class NotificationsManager
*
* This class is responsible for managing notifications.
*
* This includes sending native notifications on mobile or desktop if available as
* well as managing the push notification rules for the current active account.
*
* @note Matrix manages push notifications centrally for an account and these are
* stored on the home server. This is to allow a users settings to move between clients.
* See https://spec.matrix.org/v1.3/client-server-api/#push-rules for more
* details.
*/
class NotificationsManager : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
explicit NotificationsManager(QObject *parent = nullptr);
/**
* @brief Display a native notification for an invite.
*/
void postInviteNotification(NeoChatRoom *room);
/**
* @brief Clear an existing invite notification for the given room.
*
* Nothing happens if the given room doesn't have an invite notification.
*/
void clearInvitationNotification(const QString &roomId);
/**
* @brief Display a native notification for the given push notification.
*/
void postPushNotification(const QByteArray &message);
/**
* @brief Handle the notifications for the given connection.
*/
void handleNotifications(QPointer<NeoChatConnection> connection);
private:
QHash<QString, qint64> m_initialTimestamp;
QHash<QString, QStringList> m_oldNotifications;
QStringList m_connActiveJob;
void startNotificationJob(QPointer<NeoChatConnection> connection);
QPixmap createNotificationImage(const QImage &icon, NeoChatRoom *room);
bool shouldPostNotification(QPointer<NeoChatConnection> connection, const QJsonValue &notification);
void postNotification(NeoChatRoom *room,
const QString &sender,
const QString &text,
const QImage &icon,
const QString &replyEventId,
bool canReply,
qint64 timestamp);
void doPostInviteNotification(QPointer<NeoChatRoom> room);
QHash<QString, std::pair<qint64, KNotification *>> m_notifications;
QHash<QString, QPointer<KNotification>> m_invitations;
bool permissionAsked = false;
private Q_SLOTS:
void processNotificationJob(QPointer<NeoChatConnection> connection, Quotient::GetNotificationsJob *job, bool initialization);
};

9
src/app/notifyrc.qrc Normal file
View File

@@ -0,0 +1,9 @@
<!--
SPDX-FileCopyrightText: None
SPDX-License-Identifier: CC0-1.0
-->
<RCC>
<qresource prefix="/knotifications6">
<file>neochat.notifyrc</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: none
# SPDX-License-Identifier: CC0-1.0
[D-BUS Service]
Name=org.kde.neochat
Exec=@CMAKE_INSTALL_PREFIX@/bin/neochat --dbus-activated

View File

@@ -0,0 +1,96 @@
# SPDX-License-Identifier: CC0-1.0
# SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
[Desktop Entry]
Name=NeoChat
Name[ar]=نيوتشات
Name[ast]=NeoChat
Name[az]=NeoChat
Name[ca]=NeoChat
Name[ca@valencia]=NeoChat
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
Name[fr]=NeoChat
Name[gl]=NeoChat
Name[he]=NeoChat
Name[hi]=नियोचैट
Name[hu]=NeoChat
Name[ia]=Neochat
Name[id]=NeoChat
Name[ie]=NeoChat
Name[it]=NeoChat
Name[ka]=NeoChat
Name[ko]=NeoChat
Name[lt]=NeoChat
Name[lv]=NeoChat
Name[nl]=NeoChat
Name[nn]=NeoChat
Name[pa]=ਨਿਓ-ਚੈਟ
Name[pl]=NeoChat
Name[pt]=NeoChat
Name[pt_BR]=NeoChat
Name[ro]=NeoChat
Name[ru]=NeoChat
Name[sa]=नवचैट्
Name[sk]=NeoChat
Name[sl]=NeoChat
Name[sv]=NeoChat
Name[ta]=நியோச்சாட்
Name[tr]=NeoChat
Name[uk]=NeoChat
Name[x-test]=xxNeoChatxx
Name[zh_CN]=NeoChat
Name[zh_TW]=NeoChat
Comment=Find rooms in NeoChat
Comment[ar]=اعثر على غرف في نيوتشات
Comment[az]=NeoChat-da otaqları tapın
Comment[ca]=Cerca sales en el NeoChat
Comment[ca@valencia]=Busca sales en NeoChat
Comment[de]=Räume in NeoChat finden
Comment[el]=Εύρεση αιθουσών στο NeoChat
Comment[en_GB]=Find rooms in NeoChat
Comment[eo]=Trovi ĉambrojn en NeoChat
Comment[es]=Buscar salas en NeoChat
Comment[eu]=Bilatu gelak NeoChat-en
Comment[fi]=Etsi huoneita NeoChatissä
Comment[fr]=Trouver des salons dans NeoChat
Comment[gl]=Atopa salas en NeoChat.
Comment[he]=איתור חדרים ב־NeoChat
Comment[hi]=नियोचैट में कमरे खोजें
Comment[hu]=Szobák keresése a NeoChatben
Comment[ia]=Trova salas in NeoChat
Comment[id]=Cari ruangan di NeoChat
Comment[ie]=Trovar chambres in NeoChat
Comment[it]=Trova stanze in NeoChat
Comment[ka]=იპოვე ოთახები NeoChat-ში
Comment[ko]=NeoChat에서 대화방 찾기
Comment[lt]=Rasti kambarius NeoChat
Comment[lv]=Atrast „NeoChat“ istabas
Comment[nl]=Rooms zoeken in NeoChat
Comment[nn]=Finn rom i NeoChat
Comment[pl]=Znajdź pokoje w NeoChat
Comment[pt]=Procurar salas no NeoChat
Comment[pt_BR]=Encontrar salas no NeoChat
Comment[ru]=Поиск комнат NeoChat
Comment[sa]=NeoChat इत्यत्र कक्ष्याः अन्वेषणं कुर्वन्तु
Comment[sl]=Najdi sobe v NeoChatu
Comment[sv]=Sök efter rum i NeoChat
Comment[ta]=நியோச்சாட்டில் அரங்குகளை கண்டுபிடிக்கும்
Comment[tr]=NeoChatte odalar bulun
Comment[uk]=Пошук кімнат у NeoChat
Comment[x-test]=xxFind rooms in NeoChatxx
Comment[zh_CN]=在 NeoChat 查找聊天室
Comment[zh_TW]=在 NeoChat 尋找聊天室
X-KDE-ServiceTypes=Plasma/Runner
Type=Service
Icon=org.kde.neochat
X-Plasma-API=DBus
X-Plasma-DBusRunner-Service=org.kde.neochat
X-Plasma-DBusRunner-Path=/RoomRunner
X-Plasma-Request-Actions-Once=true
X-Plasma-Runner-Min-Letter-Count=3

View File

@@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "proxycontroller.h"
#include <QNetworkProxy>
#include <QNetworkProxyFactory>
#include "neochatconfig.h"
void ProxyController::setApplicationProxy()
{
auto cfg = NeoChatConfig::self();
QNetworkProxy proxy;
switch (cfg->proxyType()) {
case 1:
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName(cfg->proxyHost());
proxy.setPort(cfg->proxyPort());
proxy.setUser(cfg->proxyUser());
proxy.setPassword(cfg->proxyPassword());
QNetworkProxy::setApplicationProxy(proxy);
break;
case 2:
proxy.setType(QNetworkProxy::Socks5Proxy);
proxy.setHostName(cfg->proxyHost());
proxy.setPort(cfg->proxyPort());
proxy.setUser(cfg->proxyUser());
proxy.setPassword(cfg->proxyPassword());
QNetworkProxy::setApplicationProxy(proxy);
break;
case 3:
proxy.setType(QNetworkProxy::NoProxy);
QNetworkProxy::setApplicationProxy(proxy);
break;
default:
QNetworkProxyFactory::setUseSystemConfiguration(true);
break;
}
}
ProxyController::ProxyController(QObject *parent)
: QObject(parent)
{
}
#include "moc_proxycontroller.cpp"

36
src/app/proxycontroller.h Normal file
View File

@@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <QObject>
#include <QQmlEngine>
class ProxyController : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
public:
static ProxyController &instance()
{
static ProxyController _instance;
return _instance;
}
static ProxyController *create(QQmlEngine *engine, QJSEngine *)
{
engine->setObjectOwnership(&instance(), QQmlEngine::CppOwnership);
return &instance();
}
/**
* @brief Sets the QNetworkProxy for the application.
*
* @sa QNetworkProxy::setApplicationProxy
*/
Q_INVOKABLE void setApplicationProxy();
private:
explicit ProxyController(QObject *parent = nullptr);
};

113
src/app/qml/AccountMenu.qml Normal file
View File

@@ -0,0 +1,113 @@
// SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.components as KirigamiComponents
import org.kde.neochat
import org.kde.neochat.settings
import org.kde.neochat.devtools
KirigamiComponents.ConvergentContextMenu {
id: root
required property NeoChatConnection connection
required property Kirigami.ApplicationWindow window
QQC2.Action {
text: i18nc("@action:button", "Show QR Code")
icon.name: "view-barcode-qr-symbolic"
onTriggered: {
let qrMax = Qt.createComponent('org.kde.neochat', 'QrCodeMaximizeComponent').createObject(QQC2.Overlay.overlay, {
text: "https://matrix.to/#/" + root.connection.localUser.id,
title: root.connection.localUser.displayName,
subtitle: root.connection.localUser.id,
// Note: User::avatarUrl does not set user_id, and thus cannot be used directly here. Hence the makeMediaUrl.
avatarSource: root.connection.localUser.avatarUrl.toString().length > 0 ? root.connection.makeMediaUrl(root.connection.localUser.avatarUrl) : ""
});
if (typeof root.closeDialog === "function") {
root.closeDialog();
}
qrMax.open();
}
}
QQC2.Action {
text: i18n("Edit This Account")
icon.name: "document-edit"
onTriggered: pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat.settings', 'AccountEditorPage'), {
connection: root.connection
}, {
title: i18n("Account editor")
})
}
QQC2.Action {
text: i18n("Notification Settings")
icon.name: "notifications"
onTriggered: {
NeoChatSettingsView.open('notifications');
}
}
QQC2.Action {
text: i18n("Devices")
icon.name: "computer-symbolic"
onTriggered: {
NeoChatSettingsView.open('devices');
}
}
Kirigami.Action {
text: i18n("Open Developer Tools")
icon.name: "tools"
visible: NeoChatConfig.developerTools
onTriggered: pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat.devtools', 'DevtoolsPage'), {
connection: root.connection
}, {
title: i18nc("@title:window", "Developer Tools"),
width: Kirigami.Units.gridUnit * 50,
height: Kirigami.Units.gridUnit * 42
})
}
Kirigami.Action {
text: i18nc("@action:inmenu", "Open Secret Backup")
icon.name: "unlock"
visible: NeoChatConfig.secretBackup
onTriggered: root.window.pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'UnlockSSSSDialog'), {}, {
title: i18nc("@title:window", "Open Key Backup")
})
}
QQC2.Action {
text: i18nc("@action:inmenu", "Verify This Device")
icon.name: "security-low"
onTriggered: {
root.connection.startSelfVerification();
const dialog = Qt.createComponent("org.kde.kirigami", "PromptDialog").createObject(QQC2.Overlay.overlay, {
title: i18nc("@title", "Verification Request Sent"),
subtitle: i18nc("@info:label", "To proceed, accept the verification request on another device."),
standardButtons: Kirigami.Dialog.Ok
})
dialog.open();
root.connection.onNewKeyVerificationSession.connect(() => {
dialog.close();
});
}
}
QQC2.Action {
text: i18n("Logout")
icon.name: "im-kick-user"
onTriggered: confirmLogoutDialogComponent.createObject(root).open()
}
readonly property Component confirmLogoutDialogComponent: ConfirmLogoutDialog {
connection: root.connection
}
}

View File

@@ -0,0 +1,143 @@
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.neochat
Kirigami.Dialog {
id: root
required property NeoChatConnection connection
parent: applicationWindow().overlay
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
standardButtons: Kirigami.Dialog.NoButton
width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24)
title: i18nc("@title: dialog to switch between logged in accounts", "Switch Account")
onVisibleChanged: if (visible) {
accountView.forceActiveFocus()
}
contentItem: ListView {
id: accountView
property var addAccount
implicitHeight: contentHeight
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
footer: Delegates.RoundedItemDelegate {
id: addDelegate
width: parent.width
highlighted: focus && !accountView.addAccount.pressed
Component.onCompleted: accountView.addAccount = this
icon {
name: "list-add"
width: Kirigami.Units.iconSizes.smallMedium
height: Kirigami.Units.iconSizes.smallMedium
}
text: i18nc("@button: login to or register a new account.", "Add Account")
contentItem: Delegates.SubtitleContentItem {
itemDelegate: parent
subtitle: i18n("Log in or create a new account")
labelItem.textFormat: Text.PlainText
subtitleItem.textFormat: Text.PlainText
}
onClicked: {
pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat.login', 'WelcomePage'), {}, {
title: i18nc("@title:window", "Login")
});
root.close();
}
Keys.onUpPressed: {
accountView.currentIndex = accountView.count - 1;
accountView.forceActiveFocus();
}
Keys.onDownPressed: {
accountView.currentIndex = 0;
accountView.forceActiveFocus();
}
}
clip: true
model: AccountRegistry
keyNavigationEnabled: false
Keys.onDownPressed: {
if (accountView.currentIndex === accountView.count - 1) {
accountView.addAccount.forceActiveFocus();
accountView.currentIndex = -1;
} else {
accountView.incrementCurrentIndex();
}
}
Keys.onUpPressed: {
if (accountView.currentIndex === 0) {
accountView.addAccount.forceActiveFocus();
accountView.currentIndex = -1;
} else {
accountView.decrementCurrentIndex();
}
}
Keys.onEnterPressed: accountView.currentItem.clicked()
Keys.onReturnPressed: accountView.currentItem.clicked()
onVisibleChanged: {
for (let i = 0; i < accountView.count; i++) {
if (model.data(model.index(i, 0), Qt.DisplayRole) === root.connection.localUser.id) {
accountView.currentIndex = i;
break;
}
}
}
delegate: Delegates.RoundedItemDelegate {
id: userDelegate
required property NeoChatConnection connection
width: parent.width
text: connection.localUser.displayName
contentItem: RowLayout {
KirigamiComponents.Avatar {
implicitWidth: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
implicitHeight: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
sourceSize {
width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
height: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
}
source: userDelegate.connection.localUser.avatarUrl.toString().length > 0 ? userDelegate.connection.makeMediaUrl(userDelegate.connection.localUser.avatarUrl) : ""
name: userDelegate.connection.localUser.displayName ?? userDelegate.connection.localUser.id
}
Delegates.SubtitleContentItem {
itemDelegate: userDelegate
subtitle: userDelegate.connection.localUser.id
labelItem.textFormat: Text.PlainText
subtitleItem.textFormat: Text.PlainText
}
}
onClicked: {
Controller.activeConnection = userDelegate.connection;
root.close()
}
}
}
}

View File

@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
import org.kde.neochat
Kirigami.Dialog {
id: root
required property var user
width: Math.min(Kirigami.Units.gridUnit * 24, QQC2.ApplicationWindow.window.width)
height: Kirigami.Units.gridUnit * 8
standardButtons: QQC2.Dialog.Close
title: i18nc("@title:dialog", "Start a chat")
contentItem: QQC2.Label {
text: i18n("Do you want to start a chat with %1?", root.user.displayName)
textFormat: Text.PlainText
wrapMode: Text.Wrap
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
}
customFooterActions: [
Kirigami.Action {
text: i18nc("@action:button", "Start Chat")
icon.name: "im-user"
onTriggered: {
root.user.requestDirectChat();
root.close();
}
}
]
}

View File

@@ -0,0 +1,124 @@
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.de>
// SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
import org.kde.neochat
ColumnLayout {
id: root
signal attachmentCancelled
property string attachmentPath
readonly property var attachmentMimetype: FileType.mimeTypeForUrl(attachmentPath)
readonly property bool hasImage: attachmentMimetype.valid && FileType.supportedImageFormats.includes(attachmentMimetype.preferredSuffix)
readonly property string baseFileName: attachmentPath.substring(attachmentPath.lastIndexOf('/') + 1, attachmentPath.length)
RowLayout {
spacing: Kirigami.Units.smallSpacing
QQC2.Label {
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft
text: i18n("Attachment:")
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
}
QQC2.ToolButton {
id: editImageButton
visible: hasImage
icon.name: "document-edit"
text: i18n("Edit")
display: QQC2.AbstractButton.IconOnly
Component {
id: imageEditorPage
ImageEditorPage {
imagePath: root.attachmentPath
}
}
onClicked: {
let imageEditor = applicationWindow().pageStack.pushDialogLayer(imageEditorPage);
imageEditor.newPathChanged.connect(function (newPath) {
applicationWindow().pageStack.layers.pop();
root.attachmentPath = newPath;
});
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
}
QQC2.ToolButton {
id: cancelAttachmentButton
display: QQC2.AbstractButton.IconOnly
action: Kirigami.Action {
text: i18n("Cancel sending attachment")
icon.name: "dialog-close"
onTriggered: attachmentCancelled()
shortcut: "Escape"
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
}
}
Image {
id: image
Layout.alignment: Qt.AlignHCenter
asynchronous: true
cache: false // Cache is not needed. Images will rarely be shown repeatedly.
source: hasImage ? root.attachmentPath : ""
visible: hasImage
fillMode: Image.PreserveAspectFit
onSourceChanged: {
// Reset source size height, which affect implicitHeight
sourceSize.height = -1;
}
onSourceSizeChanged: {
if (implicitHeight > Kirigami.Units.gridUnit * 8) {
// This can save a lot of RAM when loading large images.
// It also improves visual quality for large images.
sourceSize.height = Kirigami.Units.gridUnit * 8;
}
}
Behavior on height {
NumberAnimation {
duration: Kirigami.Units.shortDuration
easing.type: Easing.OutCubic
}
}
}
QQC2.BusyIndicator {
id: imageBusyIndicator
visible: running
running: image.visible && image.progress < 1
}
RowLayout {
id: fileInfoLayout
Layout.alignment: Qt.AlignHCenter
spacing: parent.spacing
Kirigami.Icon {
id: mimetypeIcon
implicitWidth: Kirigami.Units.iconSizes.smallMedium
implicitHeight: Kirigami.Units.iconSizes.smallMedium
source: attachmentMimetype.iconName
}
QQC2.Label {
id: fileLabel
text: baseFileName
}
}
}

View File

@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
KirigamiComponents.Avatar {
id: root
property int notificationCount
property bool notificationHighlight
property bool showNotificationLabel
QQC2.Label {
id: notificationCountLabel
anchors.top: parent.top
anchors.right: parent.right
anchors.topMargin: -Kirigami.Units.smallSpacing
anchors.rightMargin: -Kirigami.Units.smallSpacing
z: 1
width: Math.max(notificationCountTextMetrics.advanceWidth + Kirigami.Units.smallSpacing * 2, height)
height: Kirigami.Units.iconSizes.smallMedium
text: root.notificationCount > 0 ? root.notificationCount : ""
visible: root.showNotificationLabel
color: Kirigami.Theme.textColor
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
background: Rectangle {
visible: true
Kirigami.Theme.colorSet: Kirigami.Theme.Button
Kirigami.Theme.inherit: false
color: root.notificationHighlight ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.backgroundColor
radius: height / 2
}
TextMetrics {
id: notificationCountTextMetrics
text: notificationCountLabel.text
}
}
}

View File

@@ -0,0 +1,59 @@
// SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
// SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls as QQC2
import QtQuick.Templates as T
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
Delegates.RoundedItemDelegate {
id: root
property url source
property alias notificationCount: avatarNotification.notificationCount
property alias notificationHighlight: avatarNotification.notificationHighlight
property alias showNotificationLabel: avatarNotification.showNotificationLabel
signal contextMenuRequested
signal selected
padding: Kirigami.Units.largeSpacing
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.text: text
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
Accessible.onPressAction: selected()
Keys.onSpacePressed: selected()
Keys.onEnterPressed: selected()
TapHandler {
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad | PointerDevice.Stylus
acceptedButtons: Qt.RightButton | Qt.LeftButton
onTapped: (eventPoint, button) => {
if (button === Qt.RightButton) {
root.contextMenuRequested();
} else {
root.selected();
}
}
}
TapHandler {
acceptedDevices: PointerDevice.TouchScreen
onLongPressed: root.contextMenuRequested()
}
contentItem: AvatarNotification {
id: avatarNotification
source: root.source
name: root.text
}
}

View File

@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls
import org.kde.kirigami as Kirigami
import org.kde.neochat
SearchPage {
id: root
title: i18nc("@title", "Choose a Room")
showSearchButton: false
signal chosen(string roomId)
required property NeoChatConnection connection
model: RoomManager.sortFilterRoomListModel
modelDelegate: RoomDelegate {
onClicked: {
root.chosen(currentRoom.id);
root.closeDialog();
}
connection: root.connection
openOnClick: false
}
}

View File

@@ -0,0 +1,152 @@
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigamiaddons.labs.components as Components
import org.kde.kirigami as Kirigami
import org.kde.syntaxhighlighting
import org.kde.neochat
Components.AbstractMaximizeComponent {
id: root
/**
* @brief The message author.
*/
property NeochatRoomMember author
/**
* @brief The timestamp of the message.
*/
property var time
/**
* @brief The code text to show.
*/
property string codeText
/**
* @brief The code language, if any.
*/
property string language
actions: [
Kirigami.Action {
text: i18nc("@action", "Copy to clipboard")
icon.name: "edit-copy"
onTriggered: Clipboard.saveText(root.codeText)
}
]
leading: RowLayout {
Components.Avatar {
id: userAvatar
implicitWidth: Kirigami.Units.iconSizes.medium
implicitHeight: Kirigami.Units.iconSizes.medium
name: root.author.name ?? root.author.displayName
source: root.author.avatarUrl
color: root.author.color
}
ColumnLayout {
spacing: 0
QQC2.Label {
id: userLabel
text: root.author.name ?? root.author.displayName
color: root.author.color
font.weight: Font.Bold
elide: Text.ElideRight
}
QQC2.Label {
id: dateTimeLabel
text: root.time.toLocaleString(Qt.locale(), Locale.ShortFormat)
color: Kirigami.Theme.disabledTextColor
elide: Text.ElideRight
}
}
}
content: QQC2.ScrollView {
id: codeScrollView
contentWidth: root.width
// HACK: Hide unnecessary horizontal scrollbar (https://bugreports.qt.io/browse/QTBUG-83890)
QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff
QQC2.TextArea {
id: codeText
topPadding: Kirigami.Units.smallSpacing
bottomPadding: Kirigami.Units.smallSpacing
leftPadding: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing * 2
text: root.codeText
readOnly: true
textFormat: TextEdit.PlainText
wrapMode: TextEdit.Wrap
color: Kirigami.Theme.textColor
font.family: "monospace"
Kirigami.SpellCheck.enabled: false
onWidthChanged: lineModel.resetModel()
onHeightChanged: lineModel.resetModel()
SyntaxHighlighter {
property string definitionName: Repository.definitionForName(root.language).name
textEdit: definitionName == "None" ? null : codeText
definition: definitionName
}
ColumnLayout {
id: lineNumberColumn
anchors {
top: codeText.top
topMargin: codeText.topPadding + 1
left: codeText.left
leftMargin: Kirigami.Units.smallSpacing
}
spacing: 0
Repeater {
id: repeater
model: LineModel {
id: lineModel
document: codeText.textDocument
}
delegate: QQC2.Label {
id: label
required property int index
required property int docLineHeight
Layout.fillWidth: true
Layout.preferredHeight: docLineHeight
horizontalAlignment: Text.AlignRight
text: index + 1
color: Kirigami.Theme.disabledTextColor
font.family: "monospace"
}
}
}
Kirigami.Separator {
anchors {
top: parent.top
bottom: parent.bottom
left: parent.left
leftMargin: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing
}
}
background: null
}
background: Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
color: Kirigami.Theme.backgroundColor
}
}
}

View File

@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import QtQml.Models
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
import org.kde.kitemmodels
import org.kde.neochat
QQC2.ItemDelegate {
id: root
required property NeoChatRoom currentRoom
required property bool categoryVisible
required property string filterText
required property url avatar
required property string displayName
topPadding: Kirigami.Units.largeSpacing
leftPadding: Kirigami.Units.largeSpacing
rightPadding: Kirigami.Units.largeSpacing
bottomPadding: Kirigami.Units.largeSpacing
width: ListView.view.width
height: visible ? ListView.view.width : 0
visible: root.categoryVisible || filterText.length > 0
contentItem: KirigamiComponents.Avatar {
source: root.avatar
name: root.displayName
sourceSize {
width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
height: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
}
}
onClicked: RoomManager.resolveResource(currentRoom.id)
Keys.onEnterPressed: RoomManager.resolveResource(currentRoom.id)
Keys.onReturnPressed: RoomManager.resolveResource(currentRoom.id)
QQC2.ToolTip.visible: text.length > 0 && hovered
QQC2.ToolTip.text: root.displayName ?? ""
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}

View File

@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
import org.kde.neochat
Kirigami.PromptDialog {
id: root
required property NeoChatRoom room
title: i18nc("@title:dialog", "Confirm Leaving Room")
subtitle: root.room ? i18nc("Do you really want to leave <room name>?", "Do you really want to leave %1?", root.room.displayNameForHtml) : ""
dialogType: Kirigami.PromptDialog.Warning
onRejected: {
root.close();
}
footer: QQC2.DialogButtonBox {
standardButtons: QQC2.Dialog.Cancel
QQC2.Button {
text: i18nc("@action:button", "Leave Room")
QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.AcceptRole
icon.name: "arrow-left-symbolic"
onClicked: RoomManager.leaveRoom(root.room)
}
}
}

View File

@@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
import org.kde.neochat
Kirigami.PromptDialog {
id: root
required property NeoChatConnection connection
title: i18nc("@title:dialog", "Sign out")
subtitle: i18n("Are you sure you want to sign out?")
dialogType: Kirigami.PromptDialog.Warning
onRejected: {
root.close();
}
footer: QQC2.DialogButtonBox {
standardButtons: QQC2.Dialog.Cancel
QQC2.Button {
text: i18nc("@action:button", "Sign out")
QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.AcceptRole
onClicked: {
root.connection.logout(true);
root.close();
root.accepted();
}
}
}
}

View File

@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
Kirigami.PromptDialog {
id: root
property url link
title: i18nc("@title:dialog", "Open URL")
subtitle: xi18nc("@info", "Do you want to open <link>%1</link>?", root.link)
dialogType: Kirigami.PromptDialog.Warning
standardButtons: QQC2.DialogButtonBox.Open | QQC2.DialogButtonBox.Cancel
onAccepted: {
Qt.openUrlExternally(root.link);
root.close();
}
onRejected: {
root.close();
}
}

View File

@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
import org.kde.neochat
Kirigami.Dialog {
id: root
required property string url
width: Math.min(Kirigami.Units.gridUnit * 24, QQC2.ApplicationWindow.window.width)
height: Kirigami.Units.gridUnit * 8
leftPadding: Kirigami.Units.largeSpacing
rightPadding: Kirigami.Units.largeSpacing
title: i18nc("@title:dialog", "User Consent")
contentItem: QQC2.Label {
text: i18nc("@info", "Your homeserver requires you to agree to its terms and conditions before being able to use it. Please click the button below to read them.")
wrapMode: Text.WordWrap
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
}
customFooterActions: [
Kirigami.Action {
text: i18nc("@action:button", "Open")
icon.name: "internet-services"
onTriggered: {
UrlHelper.openUrl(root.url);
root.close();
}
}
]
}

View File

@@ -0,0 +1,275 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-or-later OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.kirigamiaddons.labs.components as Components
import org.kde.neochat
FormCard.FormCardPage {
id: root
property string parentId: ""
property bool isSpace: false
property bool showChildType: false
property bool showCreateChoice: false
required property NeoChatConnection connection
signal addChild(string childId, bool setChildParent, bool canonical)
signal newChild(string childName)
title: isSpace ? i18nc("@title", "Create a Space") : i18nc("@title", "Create a Room")
Component.onCompleted: roomNameField.forceActiveFocus()
FormCard.FormHeader {
title: root.isSpace ? i18n("New Space Information") : i18n("New Room Information")
}
FormCard.FormCard {
FormCard.FormComboBoxDelegate {
id: roomTypeCombo
property bool isInitialising: true
visible: root.showChildType
text: i18n("Select type")
model: ListModel {
id: roomTypeModel
}
textRole: "text"
valueRole: "isSpace"
Component.onCompleted: {
currentIndex = indexOfValue(root.isSpace);
roomTypeModel.append({
"text": i18n("Room"),
"isSpace": false
});
roomTypeModel.append({
"text": i18n("Space"),
"isSpace": true
});
roomTypeCombo.currentIndex = 0;
roomTypeCombo.isInitialising = false;
}
onCurrentValueChanged: {
if (!isInitialising) {
root.isSpace = currentValue;
}
}
}
FormCard.FormDelegateSeparator {
visible: root.showChildType
}
FormCard.FormTextFieldDelegate {
id: roomNameField
label: i18n("Name:")
onAccepted: if (roomNameField.text.length > 0) {
roomTopicField.forceActiveFocus();
}
}
FormCard.FormDelegateSeparator {}
FormCard.FormTextFieldDelegate {
id: roomTopicField
label: i18n("Topic:")
onAccepted: ok.clicked()
}
FormCard.FormDelegateSeparator {}
FormCard.FormCheckDelegate {
id: newOfficialCheck
visible: root.parentId.length > 0
text: i18nc("@option:check As in make the space from which this dialog was created an official parent.", "Make this parent official")
checked: true
}
FormCard.FormDelegateSeparator {
visible: root.parentId.length > 0
}
FormCard.FormButtonDelegate {
id: ok
text: root.isSpace ? i18nc("@action:button", "Create Space") : i18nc("@action:button", "Create Room")
enabled: roomNameField.text.length > 0
onClicked: {
if (root.isSpace) {
root.connection.createSpace(roomNameField.text, roomTopicField.text, root.parentId, newOfficialCheck.checked);
} else {
root.connection.createRoom(roomNameField.text, roomTopicField.text, root.parentId, newOfficialCheck.checked);
}
root.newChild(roomNameField.text);
root.closeDialog();
}
}
}
FormCard.FormHeader {
visible: root.showChildType
title: i18n("Select Existing Room")
}
FormCard.FormCard {
visible: root.showChildType
FormCard.FormButtonDelegate {
visible: !chosenRoomDelegate.visible
text: i18nc("@action:button", "Pick room")
onClicked: {
let dialog = pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage'), {
connection: root.connection
}, {
title: i18nc("@title", "Explore Rooms")
});
dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
chosenRoomDelegate.roomId = roomId;
chosenRoomDelegate.displayName = displayName;
chosenRoomDelegate.avatarUrl = avatarUrl;
chosenRoomDelegate.alias = alias;
chosenRoomDelegate.topic = topic;
chosenRoomDelegate.memberCount = memberCount;
chosenRoomDelegate.isJoined = isJoined;
chosenRoomDelegate.visible = true;
});
}
}
FormCard.AbstractFormDelegate {
id: chosenRoomDelegate
property string roomId
property string displayName
property url avatarUrl
property string alias
property string topic
property int memberCount
property bool isJoined
visible: false
contentItem: RowLayout {
Components.Avatar {
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
source: chosenRoomDelegate.avatarUrl
name: chosenRoomDelegate.displayName
}
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
Kirigami.Heading {
Layout.fillWidth: true
level: 4
text: chosenRoomDelegate.displayName
font.bold: true
textFormat: Text.PlainText
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
QQC2.Label {
visible: chosenRoomDelegate.isJoined
text: i18n("Joined")
color: Kirigami.Theme.linkColor
}
}
QQC2.Label {
Layout.fillWidth: true
visible: text
text: chosenRoomDelegate.topic ? chosenRoomDelegate.topic.replace(/(\r\n\t|\n|\r\t)/gm, " ") : ""
textFormat: Text.PlainText
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
RowLayout {
Layout.fillWidth: true
Kirigami.Icon {
source: "user"
color: Kirigami.Theme.disabledTextColor
implicitHeight: Kirigami.Units.iconSizes.small
implicitWidth: Kirigami.Units.iconSizes.small
}
QQC2.Label {
text: chosenRoomDelegate.memberCount + " " + (chosenRoomDelegate.alias ?? chosenRoomDelegate.roomId)
color: Kirigami.Theme.disabledTextColor
elide: Text.ElideRight
Layout.fillWidth: true
}
}
}
}
onClicked: {
let dialog = pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage'), {
connection: root.connection
}, {
title: i18nc("@title", "Explore Rooms")
});
dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
chosenRoomDelegate.roomId = roomId;
chosenRoomDelegate.displayName = displayName;
chosenRoomDelegate.avatarUrl = avatarUrl;
chosenRoomDelegate.alias = alias;
chosenRoomDelegate.topic = topic;
chosenRoomDelegate.memberCount = memberCount;
chosenRoomDelegate.isJoined = isJoined;
chosenRoomDelegate.visible = true;
});
}
}
FormCard.FormDelegateSeparator {}
FormCard.FormCheckDelegate {
id: existingOfficialCheck
visible: root.parentId.length > 0
text: i18nc("@option:check As in make the space from which this dialog was created an official parent.", "Make this parent official")
description: enabled ? i18n("You have the required privilege level in the child to set this state") : i18n("You do not have a high enough privilege level in the child to set this state")
checked: enabled
enabled: {
if (chosenRoomDelegate.visible) {
let room = root.connection.room(chosenRoomDelegate.roomId);
if (room) {
if (room.canSendState("m.space.parent")) {
return true;
}
}
}
return false;
}
}
FormCard.FormDelegateSeparator {
visible: root.parentId.length > 0
}
FormCard.FormCheckDelegate {
id: makeCanonicalCheck
text: i18nc("@option:check The canonical parent is the default one if a room has multiple parent spaces.", "Make this space the canonical parent")
checked: enabled
enabled: existingOfficialCheck.enabled
}
FormCard.FormDelegateSeparator {}
FormCard.FormButtonDelegate {
text: i18nc("@action:button", "Ok")
enabled: chosenRoomDelegate.visible
onClicked: {
root.addChild(chosenRoomDelegate.roomId, existingOfficialCheck.checked, makeCanonicalCheck.checked);
root.closeDialog();
}
}
}
}

View File

@@ -0,0 +1,85 @@
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
import org.kde.neochat
ColumnLayout {
id: root
/**
* @brief The current room that user is viewing.
*/
required property NeoChatRoom room
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
spacing: 0
Item {
Layout.fillWidth: true
Layout.preferredHeight: Kirigami.Units.largeSpacing * 2
}
QQC2.AbstractButton {
Layout.preferredWidth: Math.round(Kirigami.Units.gridUnit * 3.5)
Layout.preferredHeight: Math.round(Kirigami.Units.gridUnit * 3.5)
Layout.alignment: Qt.AlignHCenter
onClicked: {
RoomManager.resolveResource(root.room.directChatRemoteMember.uri)
}
contentItem: KirigamiComponents.Avatar {
name: root.room ? root.room.displayName : ""
source: root.room ? root.room.avatarMediaUrl : ""
Rectangle {
visible: root.room.usesEncryption
color: Kirigami.Theme.backgroundColor
width: Kirigami.Units.gridUnit
height: Kirigami.Units.gridUnit
anchors.bottom: parent.bottom
anchors.right: parent.right
radius: Math.round(width / 2)
Kirigami.Icon {
source: "channel-secure-symbolic"
anchors.fill: parent
}
}
}
}
RowLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter
Kirigami.Icon {
id: securityIcon
//TODO figure out how to make this update
source: room.connection.isUserVerified(root.room.directChatRemoteMember.id) ?
(room.connection.allSessionsSelfVerified(root.room.directChatRemoteMember.id) ? "security-high" : "security-medium")
: "security-low"
}
Kirigami.Heading {
type: Kirigami.Heading.Type.Primary
wrapMode: QQC2.Label.Wrap
text: root.room.displayName
textFormat: Text.PlainText
horizontalAlignment: Text.AlignHCenter
}
Item {
Layout.preferredWidth: visible ? securityIcon.width : 0
visible: securityIcon.visible
}
}
}

86
src/app/qml/EditMenu.qml Normal file
View File

@@ -0,0 +1,86 @@
// SPDX-FileCopyrightText: 2021 Carson Black <uhhadd@gmail.com>
// SPDX-License-Identifier: LGPL-2.0-or-later
import Qt.labs.platform as Labs
import QtQuick
import QtQuick.Layouts
Labs.Menu {
id: root
required property Item field
Labs.MenuItem {
enabled: root.field !== null && root.field.canUndo
text: i18nc("text editing menu action", "Undo")
shortcut: StandardKey.Undo
onTriggered: {
root.field.undo();
root.close();
}
}
Labs.MenuItem {
enabled: root.field !== null && root.field.canRedo
text: i18nc("text editing menu action", "Redo")
shortcut: StandardKey.Redo
onTriggered: {
root.field.undo();
root.close();
}
}
Labs.MenuSeparator {}
Labs.MenuItem {
enabled: root.field !== null && root.field.selectedText
text: i18nc("text editing menu action", "Cut")
shortcut: StandardKey.Cut
onTriggered: {
root.field.cut();
root.close();
}
}
Labs.MenuItem {
enabled: root.field !== null && root.field.selectedText
text: i18nc("text editing menu action", "Copy")
shortcut: StandardKey.Copy
onTriggered: {
root.field.copy();
root.close();
}
}
Labs.MenuItem {
enabled: root.field !== null && root.field.canPaste
text: i18nc("text editing menu action", "Paste")
shortcut: StandardKey.Paste
onTriggered: {
root.field.paste();
root.close();
}
}
Labs.MenuItem {
enabled: root.field !== null && root.field.selectedText !== ""
text: i18nc("text editing menu action", "Delete")
shortcut: ""
onTriggered: {
root.field.remove(root.field.selectionStart, root.field.selectionEnd);
root.close();
}
}
Labs.MenuSeparator {}
Labs.MenuItem {
enabled: root.field !== null
text: i18nc("text editing menu action", "Select All")
shortcut: StandardKey.SelectAll
onTriggered: {
root.field.selectAll();
root.close();
}
}
}

View File

@@ -0,0 +1,120 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.syntaxhighlighting
import org.kde.neochat
Kirigami.Page {
id: root
required property string sourceText
property bool allowEdit: false
property NeoChatRoom room
property string type
property string stateKey
topPadding: 0
leftPadding: 0
rightPadding: 0
bottomPadding: 0
title: i18nc("@title As in 'edit the state of this room'", "Edit State")
actions: [
Kirigami.Action {
text: i18nc("@action", "Revert changes")
icon.name: "document-revert"
onTriggered: sourceTextArea.text = root.sourceText
enabled: sourceTextArea.text !== root.sourceText
},
Kirigami.Action {
text: i18nc("@action As in 'Apply the changes'", "Apply")
icon.name: "document-edit"
onTriggered: {
root.room.setRoomState(root.type, root.stateKey, sourceTextArea.text);
root.closeDialog();
}
enabled: QmlUtils.isValidJson(sourceTextArea.text)
}
]
QQC2.ScrollView {
id: scrollView
anchors.fill: parent
contentWidth: availableWidth
QQC2.TextArea {
id: sourceTextArea
Layout.fillWidth: true
leftPadding: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing * 2
text: root.sourceText
textFormat: TextEdit.PlainText
wrapMode: TextEdit.Wrap
Kirigami.SpellCheck.enabled: false
onWidthChanged: lineModel.resetModel()
onHeightChanged: lineModel.resetModel()
SyntaxHighlighter {
textEdit: sourceTextArea
definition: "JSON"
repository: Repository
}
ColumnLayout {
id: lineNumberColumn
anchors {
top: sourceTextArea.top
topMargin: sourceTextArea.topPadding
left: sourceTextArea.left
leftMargin: Kirigami.Units.smallSpacing
}
spacing: 0
Repeater {
id: repeater
model: LineModel {
id: lineModel
document: sourceTextArea.textDocument
}
delegate: QQC2.Label {
id: label
required property int index
required property int docLineHeight
Layout.fillWidth: true
Layout.preferredHeight: docLineHeight
topPadding: 1
horizontalAlignment: Text.AlignRight
text: index + 1
color: Kirigami.Theme.disabledTextColor
}
}
}
background: Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
color: Kirigami.Theme.backgroundColor
}
}
}
Kirigami.Separator {
anchors {
top: parent.top
bottom: parent.bottom
left: parent.left
leftMargin: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing
}
}
}

33
src/app/qml/EmojiItem.qml Normal file
View File

@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.neochat
ColumnLayout {
id: root
property alias emoji: emojiLabel.text
property alias description: descriptionLabel.text
QQC2.Label {
id: emojiLabel
Layout.fillWidth: true
Layout.preferredWidth: Kirigami.Units.iconSizes.huge
Layout.preferredHeight: Kirigami.Units.iconSizes.huge
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.family: "emoji"
font.pointSize: Kirigami.Theme.defaultFont.pointSize * 4
}
QQC2.Label {
id: descriptionLabel
Layout.fillWidth: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
}

25
src/app/qml/EmojiRow.qml Normal file
View File

@@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.neochat
RowLayout {
id: root
property alias model: repeater.model
spacing: Kirigami.Units.largeSpacing
Repeater {
id: repeater
delegate: EmojiItem {
emoji: modelData.emoji
description: modelData.description
}
}
}

59
src/app/qml/EmojiSas.qml Normal file
View File

@@ -0,0 +1,59 @@
// SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.neochat
ColumnLayout {
id: root
required property var model
signal accept
signal reject
spacing: Kirigami.Units.largeSpacing
Item {
Layout.fillHeight: true
}
QQC2.Label {
Layout.fillWidth: true
text: i18n("Confirm the emoji below are displayed on both devices, in the same order.")
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap
}
EmojiRow {
Layout.maximumWidth: implicitWidth
Layout.alignment: Qt.AlignHCenter
model: root.model.slice(0, 4)
}
EmojiRow {
Layout.maximumWidth: implicitWidth
Layout.alignment: Qt.AlignHCenter
model: root.model.slice(4, 7)
}
RowLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter
QQC2.Button {
anchors.bottom: parent.bottom
text: i18n("They match")
icon.name: "dialog-ok"
onClicked: root.accept()
}
QQC2.Button {
anchors.bottom: parent.bottom
text: i18n("They don't match")
icon.name: "dialog-cancel"
onClicked: root.reject()
}
}
Item {
Layout.fillHeight: true
}
}

View File

@@ -0,0 +1,140 @@
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: GPL-3.0-only
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import Qt.labs.qmlmodels
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.neochat
/**
* @brief Component for finding rooms for the public list.
*
* This component is based on a SearchPage, adding the functionality to select or
* enter a server in the header, as well as the ability to manually type a room in
* if the public room search cannot find it.
*
* @sa SearchPage
*/
SearchPage {
id: root
/**
* @brief The connection for the current local user.
*/
required property NeoChatConnection connection
/**
* @brief Whether results should only includes spaces.
*/
property bool showOnlySpaces: spacesOnlyButton.checked
onShowOnlySpacesChanged: updateSearch()
/**
* @brief Whetherthe button to toggle the showOnlySpaces state should be shown.
*/
property bool showOnlySpacesButton: true
/**
* @brief Signal emitted when a room is selected.
*
* The signal contains all the room's info so that it can be acted
* upon as required, e.g. joining or entering the room or adding the room as
* the child of a space.
*/
signal roomSelected(string roomId, string displayName, url avatarUrl, string alias, string topic, int memberCount, bool isJoined)
title: i18nc("@action:title", "Explore Rooms")
customPlaceholderText: publicRoomListModel.redirectedText
customPlaceholderIcon: "data-warning"
Component.onCompleted: focusSearch()
headerTrailing: RowLayout {
QQC2.Button {
id: spacesOnlyButton
icon.name: "globe"
display: QQC2.Button.IconOnly
checkable: true
text: i18nc("@action:button", "Only show spaces")
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.text: text
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
ServerComboBox {
id: serverComboBox
connection: root.connection
}
}
model: PublicRoomListModel {
id: publicRoomListModel
connection: root.connection
server: serverComboBox.server
showOnlySpaces: root.showOnlySpaces
}
modelDelegate: ExplorerDelegate {
onRoomSelected: (roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
root.roomSelected(roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined);
root.closeDialog();
}
}
listHeaderDelegate: Delegates.RoundedItemDelegate {
id: delegate
onClicked: _private.openManualRoomDialog()
activeFocusOnTab: false // We handle moving to this item via up/down arrows, otherwise the tab order is wacky
text: i18n("Enter a Room Manually")
visible: publicRoomListModel.redirectedText.length === 0
icon.name: "compass"
icon.width: Kirigami.Units.gridUnit * 2
icon.height: Kirigami.Units.gridUnit * 2
contentItem: Kirigami.IconTitleSubtitle {
icon: icon.fromControlsIcon(delegate.icon)
title: delegate.text
subtitle: i18n("If you already know a room's address or alias, and it isn't shown here.")
}
}
listFooterDelegate: QQC2.ProgressBar {
width: ListView.view.width
leftInset: Kirigami.Units.largeSpacing
rightInset: Kirigami.Units.largeSpacing
visible: root.count !== 0 && publicRoomListModel.searching
indeterminate: true
}
searchFieldPlaceholder: i18n("Find a room…")
noResultPlaceholderMessage: i18nc("@info:label", "No public rooms found")
Component {
id: manualRoomDialog
ManualRoomDialog {}
}
QtObject {
id: _private
function openManualRoomDialog() {
let dialog = manualRoomDialog.createObject(root.QQC2.Overlay.overlay, {
connection: root.connection
});
dialog.parent = root.Window.window.overlay;
dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
root.roomSelected(roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined);
root.closeDialog();
});
dialog.open();
}
}
}

View File

@@ -0,0 +1,106 @@
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.kirigamiaddons.labs.components as Components
import org.kde.neochat
Delegates.RoundedItemDelegate {
id: root
required property string roomId
required property string displayName
required property url avatarUrl
required property string alias
required property string topic
required property int memberCount
required property bool isJoined
required property bool isSpace
property bool justJoined: false
/**
* @brief Signal emitted when a room delegate is selected.
*
* The signal contains all the delegate's model info so that it can be acted
* upon as required, e.g. joining or entering the room or adding the room as
* the child of a space.
*/
signal roomSelected(string roomId, string displayName, url avatarUrl, string alias, string topic, int memberCount, bool isJoined)
onClicked: {
if (!isJoined) {
justJoined = true;
}
root.roomSelected(root.roomId, root.displayName, root.avatarUrl, root.alias, root.topic, root.memberCount, root.isJoined);
}
contentItem: RowLayout {
spacing: Kirigami.Units.smallSpacing
Components.Avatar {
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
Layout.alignment: Qt.AlignTop
source: root.avatarUrl
name: root.displayName
}
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
Kirigami.Heading {
Layout.fillWidth: !spaceLabel.visible
level: 4
text: root.displayName
font.bold: true
textFormat: Text.PlainText
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
QQC2.Label {
id: spaceLabel
Layout.fillWidth: true
visible: root.isSpace
text: i18nc("@info:label A matrix space", "Space")
color: Kirigami.Theme.linkColor
}
QQC2.Label {
visible: root.isJoined || root.justJoined
text: i18n("Joined")
color: Kirigami.Theme.linkColor
}
}
QQC2.Label {
Layout.fillWidth: true
visible: text
text: root.topic ? root.topic.replace(/(\r\n\t|\n|\r\t)/gm, " ") : ""
textFormat: Text.PlainText
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
RowLayout {
Layout.fillWidth: true
Kirigami.Icon {
source: "user"
color: Kirigami.Theme.disabledTextColor
implicitHeight: Kirigami.Units.iconSizes.small
implicitWidth: Kirigami.Units.iconSizes.small
}
QQC2.Label {
text: root.memberCount + " " + (root.alias ?? root.roomId)
color: Kirigami.Theme.disabledTextColor
elide: Text.ElideRight
Layout.fillWidth: true
}
}
}
}
}

View File

@@ -0,0 +1,79 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls
import QtLocation
import QtPositioning
import org.kde.kirigami as Kirigami
ApplicationWindow {
id: root
property real latitude: NaN
property real longitude: NaN
property string asset
property var author
property QtObject liveLocationModel: null
flags: Qt.FramelessWindowHint | Qt.WA_TranslucentBackground
visibility: Qt.WindowFullScreen
title: i18n("View Location")
Shortcut {
sequence: "Escape"
onActivated: root.destroy()
}
color: Kirigami.Theme.backgroundColor
background: AbstractButton {
onClicked: root.destroy()
}
MapView {
id: mapView
anchors.fill: parent
map.center: root.liveLocationModel ? QtPositioning.coordinate(root.liveLocationModel.boundingBox.y, root.liveLocationModel.boundingBox.x) : QtPositioning.coordinate(root.latitude, root.longitude)
map.zoomLevel: 15
map.plugin: OsmLocationPlugin.plugin
LocationMapItem {
latitude: root.latitude
longitude: root.longitude
asset: root.asset
author: root.author
isLive: true
heading: NaN
visible: !isNaN(root.latitude) && !isNaN(root.longitude)
Component.onCompleted: mapView.map.addMapItem(this)
}
MapItemView {
model: root.liveLocationModel
delegate: LocationMapItem {}
Component.onCompleted: mapView.map.addMapItemView(this)
}
Connections {
target: mapView.map
function onCopyrightLinkActivated() {
Qt.openUrlExternally(link);
}
}
}
Button {
anchors.top: parent.top
anchors.right: parent.right
text: i18n("Close")
icon.name: "dialog-close"
display: AbstractButton.IconOnly
width: Kirigami.Units.gridUnit * 2
height: Kirigami.Units.gridUnit * 2
onClicked: root.destroy()
}
}

108
src/app/qml/GlobalMenu.qml Normal file
View File

@@ -0,0 +1,108 @@
// SPDX-FileCopyrightText: 2021 Carson Black <uhhadd@gmail.com>
// SPDX-License-Identifier: GPL-3.0-or-later
import Qt.labs.platform as Labs
import QtQuick
import QtQuick.Window
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.neochat
import org.kde.neochat.settings
Labs.MenuBar {
id: root
property NeoChatConnection connection
Labs.Menu {
title: i18nc("menu", "NeoChat")
Labs.MenuItem {
enabled: pageStack.layers.currentItem.title !== i18n("Configure NeoChat…")
text: i18nc("menu", "Configure NeoChat…")
shortcut: StandardKey.Preferences
onTriggered: NeoChatSettingsView.open()
}
Labs.MenuItem {
text: i18nc("menu", "Quit NeoChat")
shortcut: StandardKey.Quit
onTriggered: Qt.quit()
}
}
Labs.Menu {
title: i18nc("menu", "File")
Labs.MenuItem {
text: i18nc("menu", "Find your friends")
enabled: pageStack.layers.currentItem.title !== i18n("Find your friends") && AccountRegistry.accountCount > 0
onTriggered: pushReplaceLayer(Qt.createComponent('org.kde.neochat', 'UserSearchPage'), {
connection: root.connection
}, {
title: i18nc("@title", "Find your friends")
})
}
Labs.MenuItem {
text: i18nc("menu", "New Group…")
enabled: pageStack.layers.currentItem.title !== i18n("Find your friends") && AccountRegistry.accountCount > 0
shortcut: StandardKey.New
onTriggered: {
const dialog = createRoomDialog.createObject(root.overlay);
dialog.open();
}
}
Labs.MenuItem {
text: i18nc("menu", "Browse Chats…")
onTriggered: {
let dialog = pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage'), {
connection: root.connection
}, {
title: i18nc("@title", "Explore Rooms")
});
dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
RoomManager.resolveResource(roomId.length > 0 ? roomId : alias, isJoined ? "" : "join");
});
}
}
}
EditMenu {
title: i18nc("menu", "Edit")
field: (root.activeFocusItem instanceof TextEdit || root.activeFocusItem instanceof TextInput) ? root.activeFocusItem : null
}
Labs.Menu {
title: i18nc("menu", "View")
Labs.MenuItem {
text: i18nc("menu item that opens a UI element called the 'Quick Switcher', which offers a fast keyboard-based interface for switching in between chats.", "Open Quick Switcher")
onTriggered: quickSwitcher.open()
}
}
Labs.Menu {
title: i18nc("menu", "Window")
Labs.MenuItem {
text: root.visibility === Window.FullScreen ? i18nc("menu", "Exit Full Screen") : i18nc("menu", "Enter Full Screen")
onTriggered: root.visibility === Window.FullScreen ? root.showNormal() : root.showFullScreen()
}
}
Labs.Menu {
title: i18nc("menu", "Help")
Labs.MenuItem {
text: i18nc("menu", "About Matrix")
onTriggered: UrlHelper.openUrl("https://matrix.org/docs/chat_basics/matrix-for-im/")
}
Labs.MenuItem {
text: i18nc("menu", "About NeoChat")
onTriggered: pageStack.pushDialogLayer(Qt.createComponent("org.kde.kirigamiaddons.formcard", "AboutPage"))
}
Labs.MenuItem {
text: i18nc("menu", "About KDE")
onTriggered: pageStack.pushDialogLayer(Qt.createComponent("org.kde.kirigamiaddons.formcard", "AboutKDEPage"))
}
}
}

View File

@@ -0,0 +1,124 @@
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
import org.kde.prison
import org.kde.neochat
ColumnLayout {
id: root
/**
* @brief The current room that user is viewing.
*/
required property NeoChatRoom room
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
Layout.leftMargin: Kirigami.Units.largeSpacing
Layout.topMargin: Kirigami.Units.largeSpacing
Layout.bottomMargin: Kirigami.Units.largeSpacing
spacing: Kirigami.Units.largeSpacing
KirigamiComponents.Avatar {
Layout.preferredWidth: Kirigami.Units.iconSizes.large
Layout.preferredHeight: Kirigami.Units.iconSizes.large
name: root.room ? root.room.displayName : ""
source: root.room ? root.room.avatarMediaUrl : ""
Rectangle {
visible: room.usesEncryption
color: Kirigami.Theme.backgroundColor
width: Kirigami.Units.gridUnit
height: Kirigami.Units.gridUnit
anchors {
bottom: parent.bottom
right: parent.right
}
radius: Math.round(width / 2)
Kirigami.Icon {
source: "channel-secure-symbolic"
anchors.fill: parent
}
}
}
ColumnLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
spacing: 0
Kirigami.Heading {
Layout.fillWidth: true
text: root.room ? root.room.displayName : i18n("No name")
textFormat: Text.PlainText
wrapMode: Text.Wrap
}
Kirigami.SelectableLabel {
Layout.fillWidth: true
font: Kirigami.Theme.smallFont
textFormat: TextEdit.PlainText
visible: root.room && root.room.canonicalAlias
text: root.room && root.room.canonicalAlias ? root.room.canonicalAlias : ""
color: Kirigami.Theme.disabledTextColor
}
}
QQC2.AbstractButton {
Layout.preferredWidth: Kirigami.Units.iconSizes.large
Layout.preferredHeight: Kirigami.Units.iconSizes.large
Layout.rightMargin: Kirigami.Units.largeSpacing
contentItem: Barcode {
id: barcode
barcodeType: Barcode.QRCode
content: "https://matrix.to/#/" + root.room.id
}
onClicked: {
let map = Qt.createComponent('org.kde.neochat', 'QrCodeMaximizeComponent').createObject(QQC2.Overlay.overlay, {
text: barcode.content,
title: root.room ? root.room.displayName : "",
subtitle: root.room ? root.room.id : "",
avatarSource: root.room ? root.room.avatarMediaUrl : ""
});
map.open();
}
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.text: barcode.content
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
}
Kirigami.SelectableLabel {
Layout.fillWidth: true
Layout.leftMargin: Kirigami.Units.largeSpacing
Layout.rightMargin: Kirigami.Units.largeSpacing
visible: text.length > 0
text: root.room && root.room.topic ? root.room.topic : ""
textFormat: TextEdit.MarkdownText
wrapMode: Text.Wrap
onLinkActivated: link => UrlHelper.openUrl(link)
onHoveredLinkChanged: if (hoveredLink.length > 0 && hoveredLink !== "1") {
applicationWindow().hoverLinkIndicator.text = hoveredLink;
} else {
applicationWindow().hoverLinkIndicator.text = "";
}
}
}

View File

@@ -0,0 +1,181 @@
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.neochat
import org.kde.neochat.chatbar
/**
* @brief A component that provides a set of actions when a message is hovered in the timeline.
*
* There is also an icon to show that a message has come from a verified device in
* encrypted chats.
*/
QQC2.Control {
id: root
/**
* @brief The current message delegate the actions are being shown on.
*/
property var delegate: null
/**
* @brief The current room that user is viewing.
*/
required property NeoChatRoom currentRoom
/**
* @brief Whether the actions should be shown.
*/
readonly property bool showActions: delegate && delegate.hovered
/**
* @brief Request that the chat bar be focussed.
*/
signal focusChatBar
topPadding: 0
bottomPadding: 0
leftPadding: 0
rightPadding: 0
visible: (root.hovered || root.showActions || showActionsTimer.running) && !Kirigami.Settings.isMobile && (!root.delegate.isThreaded || !NeoChatConfig.threads)
onVisibleChanged: {
if (visible) {
// HACK: delay disapearing by 200ms, otherwise this can create some glitches
// See https://invent.kde.org/network/neochat/-/issues/333
showActionsTimer.restart();
}
}
Timer {
id: showActionsTimer
interval: 200
}
function updatePosition(): void {
if (delegate) {
root.x = delegate.contentItem.x + delegate.bubbleX + delegate.bubbleWidth - root.implicitWidth;
root.y = delegate.mapToItem(parent, 0, 0).y + delegate.bubbleY - height + Kirigami.Units.smallSpacing;
}
}
onDelegateChanged: updatePosition()
onWidthChanged: updatePosition()
contentItem: RowLayout {
id: actionsLayout
spacing: Kirigami.Units.smallSpacing
Item {
Layout.fillWidth: true
}
Kirigami.Icon {
source: "security-high"
width: height
height: root.height
visible: root.delegate && root.delegate.verified
HoverHandler {
id: hover
}
QQC2.ToolTip.text: i18n("This message was sent from a verified device")
QQC2.ToolTip.visible: hover.hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.Button {
text: i18n("React")
icon.name: "preferences-desktop-emoticons"
onClicked: emojiDialog.open()
display: QQC2.ToolButton.IconOnly
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.Button {
visible: root.delegate && root.delegate.isEditable && !root.currentRoom.readOnly
text: i18n("Edit")
icon.name: "document-edit"
display: QQC2.Button.IconOnly
onClicked: {
root.currentRoom.editCache.editId = root.delegate.eventId;
root.currentRoom.mainCache.replyId = "";
root.currentRoom.mainCache.threadId = "";
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.Button {
visible: !root.currentRoom.readOnly
text: i18n("Reply")
icon.name: "mail-replied-symbolic"
display: QQC2.Button.IconOnly
onClicked: {
root.currentRoom.mainCache.replyId = root.delegate.eventId;
root.currentRoom.editCache.editId = "";
root.currentRoom.mainCache.threadId = "";
root.focusChatBar();
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.Button {
visible: NeoChatConfig.threads && !root.currentRoom.readOnly && !root.delegate?.isPoll
text: i18n("Reply in Thread")
icon.name: "dialog-messages"
display: QQC2.Button.IconOnly
onClicked: {
root.currentRoom.threadCache.replyId = "";
root.currentRoom.threadCache.threadId = root.delegate.isThreaded ? root.delegate.threadRoot : root.delegate.eventId;
root.currentRoom.mainCache.clearRelations();
root.currentRoom.editCache.clearRelations();
root.focusChatBar();
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.Button {
visible: (root.delegate?.isPoll ?? false) && !ContentProvider.handlerForPoll(root.currentRoom, root.delegate.eventId).hasEnded
text: i18n("End Poll")
icon.name: "gtk-stop"
display: QQC2.ToolButton.IconOnly
onClicked: root.currentRoom.poll(root.delegate.eventId).endPoll()
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
EmojiDialog {
id: emojiDialog
currentRoom: root.currentRoom
showQuickReaction: true
showStickers: false
onChosen: emoji => {
root.currentRoom.toggleReaction(root.delegate.eventId, emoji);
if (!Kirigami.Settings.isMobile) {
root.focusChatBar();
}
}
}
}
}

View File

@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
QQC2.Control {
id: root
property string text
visible: !root.text.startsWith("https://matrix.to/") && root.text.length > 0
Kirigami.Theme.colorSet: Kirigami.Theme.View
z: 20
Accessible.ignored: true
contentItem: QQC2.Label {
text: root.text.startsWith("https://matrix.to/") ? "" : root.text
elide: Text.ElideRight
Accessible.description: i18nc("@info screenreader", "The currently selected link")
}
background: Rectangle {
color: Kirigami.Theme.backgroundColor
}
}

View File

@@ -0,0 +1,177 @@
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: BSD-2-Clause
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import QtCore as Core
import org.kde.kirigami as Kirigami
import org.kde.kquickimageeditor as KQuickImageEditor
Kirigami.Page {
id: rootEditorView
property bool resizing: false
required property string imagePath
signal newPathChanged(string newPath)
title: i18n("Edit")
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
function crop() {
const ratioX = editImage.paintedWidth / editImage.nativeWidth;
const ratioY = editImage.paintedHeight / editImage.nativeHeight;
rootEditorView.resizing = false;
imageDoc.crop(selectionTool.selectionX / ratioX, selectionTool.selectionY / ratioY, selectionTool.selectionWidth / ratioX, selectionTool.selectionHeight / ratioY);
}
actions: [
Kirigami.Action {
id: undoAction
text: i18nc("@action:button Undo modification", "Undo")
icon.name: "edit-undo"
onTriggered: imageDoc.undo()
visible: imageDoc.edited
},
Kirigami.Action {
id: okAction
text: i18nc("@action:button Accept image modification", "Accept")
icon.name: "dialog-ok"
onTriggered: {
let newPath = Core.StandardPaths.writableLocation(Core.StandardPaths.CacheLocation) + "/" + (new Date()).getTime() + "." + imagePath.split('.').pop();
if (imageDoc.saveAs(newPath)) {
newPathChanged(newPath);
} else {
msg.type = Kirigami.MessageType.Error;
msg.text = i18n("Unable to save file. Check if you have the correct permission to edit the cache directory.");
msg.visible = true;
}
}
}
]
KQuickImageEditor.ImageItem {
id: editImage
// Assigning this to the contentItem and setting the padding causes weird positioning issues
anchors.fill: parent
anchors.margins: Kirigami.Units.gridUnit
fillMode: KQuickImageEditor.ImageItem.PreserveAspectFit
image: imageDoc.image
Shortcut {
sequence: StandardKey.Undo
onActivated: undoAction.trigger()
}
Shortcut {
sequences: [StandardKey.Save, "Enter"]
onActivated: saveAction.trigger()
}
Shortcut {
sequence: StandardKey.SaveAs
onActivated: saveAsAction.trigger()
}
KQuickImageEditor.ImageDocument {
id: imageDoc
path: rootEditorView.imagePath
}
KQuickImageEditor.SelectionTool {
id: selectionTool
visible: rootEditorView.resizing
width: editImage.paintedWidth
height: editImage.paintedHeight
x: editImage.horizontalPadding
y: editImage.verticalPadding
KQuickImageEditor.CropBackground {
anchors.fill: parent
z: -1
insideX: selectionTool.selectionX
insideY: selectionTool.selectionY
insideWidth: selectionTool.selectionWidth
insideHeight: selectionTool.selectionHeight
}
Connections {
target: selectionTool.selectionArea
function onDoubleClicked() {
rootEditorView.crop();
}
}
}
onImageChanged: {
selectionTool.selectionX = 0;
selectionTool.selectionY = 0;
selectionTool.selectionWidth = Qt.binding(() => selectionTool.width);
selectionTool.selectionHeight = Qt.binding(() => selectionTool.height);
}
}
header: QQC2.ToolBar {
contentItem: Kirigami.ActionToolBar {
id: actionToolBar
display: QQC2.Button.TextBesideIcon
actions: [
Kirigami.Action {
icon.name: rootEditorView.resizing ? "dialog-cancel" : "transform-crop"
text: rootEditorView.resizing ? i18n("Cancel") : i18nc("@action:button Crop an image", "Crop")
onTriggered: {
resizeRectangle.width = editImage.paintedWidth;
resizeRectangle.height = editImage.paintedHeight;
resizeRectangle.x = editImage.horizontalPadding;
resizeRectangle.y = editImage.verticalPadding;
resizeRectangle.insideX = 100;
resizeRectangle.insideY = 100;
resizeRectangle.insideWidth = 100;
resizeRectangle.insideHeight = 100;
rootEditorView.resizing = !rootEditorView.resizing;
}
},
Kirigami.Action {
icon.name: "dialog-ok"
visible: rootEditorView.resizing
text: i18nc("@action:button Crop an image", "Crop")
onTriggered: rootEditorView.crop()
},
Kirigami.Action {
icon.name: "object-rotate-left"
text: i18nc("@action:button Rotate an image to the left", "Rotate left")
onTriggered: imageDoc.rotate(-90)
visible: !rootEditorView.resizing
},
Kirigami.Action {
icon.name: "object-rotate-right"
text: i18nc("@action:button Rotate an image to the right", "Rotate right")
onTriggered: imageDoc.rotate(90)
visible: !rootEditorView.resizing
},
Kirigami.Action {
icon.name: "object-flip-vertical"
text: i18nc("@action:button Mirror an image vertically", "Flip")
onTriggered: imageDoc.mirror(false, true)
visible: !rootEditorView.resizing
},
Kirigami.Action {
icon.name: "object-flip-horizontal"
text: i18nc("@action:button Mirror an image horizontally", "Mirror")
onTriggered: imageDoc.mirror(true, false)
visible: !rootEditorView.resizing
}
]
}
}
footer: Kirigami.InlineMessage {
id: msg
type: Kirigami.MessageType.Error
showCloseButton: true
visible: false
position: Kirigami.InlineMessage.Position.Header
}
}

View File

@@ -0,0 +1,115 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-FileCopyrightText: 2025 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.components as KirigamiComponents
import org.kde.neochat
ColumnLayout {
id: root
required property NeoChatRoom currentRoom
readonly property var invitingMember: currentRoom.member(currentRoom.invitingUserId())
spacing: Kirigami.Units.smallSpacing
KirigamiComponents.Avatar {
id: avatar
Layout.preferredWidth: Kirigami.Units.iconSizes.huge
Layout.preferredHeight: Kirigami.Units.iconSizes.huge
Layout.alignment: Qt.AlignHCenter
name: root.invitingMember.displayName
source: root.invitingMember.avatarUrl
color: root.invitingMember.color
}
Loader {
active: !root.currentRoom.isDirectChat()
Layout.alignment: Qt.AlignHCenter
sourceComponent: ColumnLayout {
spacing: Kirigami.Units.smallSpacing
QQC2.Label {
text: i18nc("@info:label", "%1 has invited you to join", root.invitingMember.displayName)
Layout.alignment: Qt.AlignHCenter
}
Kirigami.Heading {
text: root.currentRoom.displayName
Layout.alignment: Qt.AlignHCenter
}
}
}
Loader {
active: root.currentRoom.isDirectChat()
Layout.alignment: Qt.AlignHCenter
sourceComponent: ColumnLayout {
spacing: Kirigami.Units.smallSpacing
Kirigami.Heading {
text: root.currentRoom.displayName
Layout.alignment: Qt.AlignHCenter
}
QQC2.Label {
text: i18nc("@info:label", "This user is inviting you to chat.")
Layout.alignment: Qt.AlignHCenter
}
}
}
QQC2.Label {
color: Kirigami.Theme.disabledTextColor
text: i18n("You can reject invitations from unknown users under Security settings.")
visible: root.currentRoom.connection.canCheckMutualRooms
}
RowLayout {
spacing: Kirigami.Units.smallSpacing
Layout.alignment: Qt.AlignHCenter
Layout.topMargin: Kirigami.Units.mediumSpacing
QQC2.Button {
Layout.alignment: Qt.AlignHCenter
text: i18nc("@action:button The thing being rejected is an invitation to chat", "Reject and Ignore User")
icon.name: "list-remove-symbolic"
onClicked: {
RoomManager.leaveRoom(root.currentRoom);
root.currentRoom.connection.addToIgnoredUsers(root.currentRoom.invitingUserId());
}
}
QQC2.Button {
Layout.alignment: Qt.AlignHCenter
icon.name: "cards-block-symbolic"
text: i18nc("@action:button", "Reject")
onClicked: RoomManager.leaveRoom(root.currentRoom)
}
QQC2.Button {
Layout.alignment: Qt.AlignHCenter
icon.name: "dialog-ok-symbolic"
text: i18nc("@action:button", "Accept")
onClicked: root.currentRoom.acceptInvitation()
}
}
}

View File

@@ -0,0 +1,90 @@
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
// SPDX-License-Identifier: GPL-3.0-only
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
import org.kde.neochat
SearchPage {
id: root
property NeoChatRoom room
title: i18nc("@title:dialog", "Invite a User")
searchFieldPlaceholder: i18nc("@info:placeholder", "Find a user…")
noResultPlaceholderMessage: i18nc("@info:placeholder", "No users found")
headerTrailing: QQC2.Button {
icon.name: "list-add"
display: QQC2.Button.IconOnly
enabled: root.model.searchText.match(/@(.+):(.+)/g) && !root.room.containsUser(root.model.searchText)
text: i18nc("@action:button", "Invite this User")
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.text: root.room.containsUser(root.model.searchText) ? i18nc("@info:tooltip", "User is either already a member or has been invited") : text
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
onClicked: root.room.inviteToRoom(root.model.searchText);
}
model: UserDirectoryListModel {
id: userDictListModel
connection: root.room.connection
}
modelDelegate: Delegates.RoundedItemDelegate {
id: delegate
required property string userId
required property string displayName
required property url avatarUrl
text: displayName
contentItem: RowLayout {
KirigamiComponents.Avatar {
Layout.preferredWidth: Kirigami.Units.iconSizes.medium
Layout.preferredHeight: Kirigami.Units.iconSizes.medium
source: delegate.avatarUrl
name: delegate.displayName
}
Delegates.SubtitleContentItem {
itemDelegate: delegate
subtitle: delegate.userId
labelItem.textFormat: Text.PlainText
}
QQC2.ToolButton {
id: inviteButton
readonly property bool inRoom: root.room && root.room.containsUser(delegate.userId)
icon.name: "document-send"
text: i18nc("@action:button", "Send invitation")
opacity: inRoom ? 0.5 : 1
enabled: !inRoom
onClicked: {
inviteButton.enabled = false;
root.room.inviteToRoom(delegate.userId);
}
QQC2.ToolTip.text: !inRoom ? text : i18nc("@info:tooltip", "User is either already a member or has been invited")
QQC2.ToolTip.visible: inviteButton.hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
}
}
}

View File

@@ -0,0 +1,75 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.components as KirigamiComponents
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.prison
import org.kde.neochat
Kirigami.Dialog {
id: root
required property string room
required property NeoChatConnection connection
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
standardButtons: Kirigami.Dialog.NoButton
width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24)
title: i18nc("@title:dialog", "Join Room")
contentItem: ColumnLayout {
spacing: 0
RowLayout {
Layout.fillWidth: true
Layout.leftMargin: Kirigami.Units.largeSpacing
Layout.rightMargin: Kirigami.Units.largeSpacing
Layout.topMargin: Kirigami.Units.largeSpacing
Layout.bottomMargin: Kirigami.Units.largeSpacing
spacing: Kirigami.Units.largeSpacing
KirigamiComponents.Avatar {
id: avatar
Layout.preferredWidth: Kirigami.Units.iconSizes.huge
Layout.preferredHeight: Kirigami.Units.iconSizes.huge
name: root.room.slice(1, -1)
initialsMode: KirigamiComponents.Avatar.UseInitials
}
Kirigami.Heading {
level: 1
Layout.fillWidth: true
font.bold: true
elide: Text.ElideRight
wrapMode: Text.NoWrap
text: root.room
textFormat: Text.PlainText
}
}
Kirigami.Separator {
Layout.fillWidth: true
}
FormCard.FormButtonDelegate {
text: i18nc("@action:button", "Join room")
icon.name: "irc-join-channel"
onClicked: {
RoomManager.resolveResource(root.room, "join");
root.close();
}
}
}
}

View File

@@ -0,0 +1,173 @@
// SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import QtQml
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.neochat
Kirigami.Page {
id: root
title: i18n("Session Verification")
required property var session
states: [
State {
name: "cancelled"
when: root.session.state === KeyVerificationSession.CANCELED
PropertyChanges {
target: stateLoader
sourceComponent: verificationCanceled
}
},
State {
name: "waitingForVerification"
when: root.session.state === KeyVerificationSession.WAITINGFORVERIFICATION
PropertyChanges {
target: stateLoader
sourceComponent: emojiSas
}
},
State {
name: "waitingForReady"
when: root.session.state === KeyVerificationSession.WAITINGFORREADY
PropertyChanges {
target: stateLoader
sourceComponent: message
}
},
State {
name: "incoming"
when: root.session.state === KeyVerificationSession.INCOMING
PropertyChanges {
target: stateLoader
sourceComponent: message
}
},
State {
name: "waitingForMac"
when: root.session.state === KeyVerificationSession.WAITINGFORMAC
PropertyChanges {
target: stateLoader
sourceComponent: message
}
},
State {
name: "ready"
when: root.session.state === KeyVerificationSession.READY
PropertyChanges {
target: stateLoader
sourceComponent: chooseVerificationComponent
}
},
State {
name: "done"
when: root.session.state === KeyVerificationSession.DONE
PropertyChanges {
target: stateLoader
sourceComponent: message
}
}
]
Loader {
id: stateLoader
anchors.fill: parent
}
footer: QQC2.ToolBar {
visible: root.session.state === KeyVerificationSession.INCOMING
QQC2.DialogButtonBox {
anchors.fill: parent
Item {
Layout.fillWidth: true
}
QQC2.Button {
text: i18n("Accept")
icon.name: "dialog-ok"
onClicked: root.session.sendReady()
QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.AcceptRole
}
QQC2.Button {
text: i18n("Decline")
icon.name: "dialog-cancel"
onClicked: root.session.cancelVerification("m.user", "Declined")
QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.RejectRole
}
}
}
Component {
id: verificationCanceled
VerificationCanceled {
reason: root.session.error
}
}
Component {
id: emojiSas
EmojiSas {
model: root.session.sasEmojis
onReject: root.session.cancelVerification(KeyVerificationSession.MISMATCHED_SAS)
onAccept: root.session.sendMac()
}
}
Component {
id: message
VerificationMessage {
icon: {
switch (root.session.state) {
case KeyVerificationSession.WAITINGFORREADY:
case KeyVerificationSession.INCOMING:
case KeyVerificationSession.WAITINGFORMAC:
return "security-medium-symbolic";
case KeyVerificationSession.DONE:
return "security-high";
default:
return "";
}
}
text: {
switch (root.session.state) {
case KeyVerificationSession.WAITINGFORREADY:
return i18n("Waiting for device to accept verification.");
case KeyVerificationSession.INCOMING:
return i18n("Incoming key verification request from device **%1**", root.session.remoteDeviceId);
case KeyVerificationSession.WAITINGFORMAC:
return i18n("Waiting for other party to verify.");
case KeyVerificationSession.DONE:
return i18n("Successfully verified device **%1**", root.session.remoteDeviceId)
default:
return "";
}
}
}
}
Component {
id: chooseVerificationComponent
Item {
ColumnLayout {
anchors.centerIn: parent
spacing: Kirigami.Units.largeSpacing
QQC2.Label {
text: i18nc("@info", "Choose a verification method to continue")
}
QQC2.Button {
id: emojiVerification
text: i18nc("@action:button", "Emoji Verification")
icon.name: "smiley"
onClicked: root.session.sendStartSas()
Layout.alignment: Qt.AlignHCenter
}
}
}
}
}

View File

@@ -0,0 +1,100 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtLocation
import QtPositioning
import org.kde.kirigamiaddons.labs.components as Components
import org.kde.kirigami as Kirigami
import org.kde.neochat
Components.AbstractMaximizeComponent {
id: root
required property NeoChatRoom room
property var location
title: i18n("Choose a Location")
actions: [
Kirigami.Action {
icon.name: "document-send"
text: i18n("Send this location")
onTriggered: {
root.room.sendLocation(root.location.latitude, root.location.longitude, "");
root.close();
}
enabled: !!root.location
},
Kirigami.Action {
text: i18nc("@action:intoolbar Re-center the map onto the set location", "Re-Center")
icon.name: "snap-bounding-box-center-symbolic"
onTriggered: mapView.map.fitViewportToMapItems([mapView.locationMapItem])
enabled: root.location !== undefined
},
Kirigami.Action {
text: i18nc("@action:intoolbar Determine the device's location", "Locate")
icon.name: "mark-location-symbolic"
enabled: positionSource.valid
onTriggered: positionSource.update()
}
]
PositionSource {
id: positionSource
active: false
onPositionChanged: {
const coord = position.coordinate;
mapView.gpsMapItem.latitude = coord.latitude;
mapView.gpsMapItem.longitude = coord.longitude;
mapView.map.addMapItem(mapView.gpsMapItem);
mapView.map.fitViewportToMapItems([mapView.gpsMapItem])
}
}
content: MapView {
id: mapView
map.plugin: OsmLocationPlugin.plugin
MouseArea {
anchors.fill: parent
onClicked: {
root.location = mapView.map.toCoordinate(Qt.point(mouseX, mouseY), false);
mapView.map.addMapItem(mapView.locationMapItem);
}
}
readonly property LocationMapItem locationMapItem: LocationMapItem {
latitude: root.location.latitude
longitude: root.location.longitude
isLive: false
heading: NaN
asset: ""
author: null
}
readonly property LocationMapItem gpsMapItem: LocationMapItem {
latitude: 0.0
longitude: 0.0
isLive: true
heading: NaN
asset: ""
author: null
}
Connections {
target: mapView.map
function onCopyrightLinkActivated(link: string) {
Qt.openUrlExternally(link);
}
}
}
}

View File

@@ -0,0 +1,76 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtLocation
import QtPositioning
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
import org.kde.neochat
/** Location marker for any of the shared location maps. */
MapQuickItem {
id: root
required property real latitude
required property real longitude
required property string asset
required property var author
required property bool isLive
required property real heading
anchorPoint.x: sourceItem.width / 2
anchorPoint.y: sourceItem.height
coordinate: QtPositioning.coordinate(root.latitude, root.longitude)
autoFadeIn: false
sourceItem: Kirigami.Icon {
id: mainIcon
width: height
height: Kirigami.Units.iconSizes.huge
source: "gps"
isMask: true
color: root.isLive ? Kirigami.Theme.highlightColor : Kirigami.Theme.disabledTextColor
Kirigami.Icon {
anchors.centerIn: parent
anchors.verticalCenterOffset: -parent.height / 8
visible: root.asset === "m.pin"
width: height
height: parent.height / 3 + 1
source: "pin"
isMask: true
color: parent.color
}
KirigamiComponents.Avatar {
anchors.centerIn: parent
anchors.verticalCenterOffset: -parent.height / 8
visible: root.asset === "m.self"
width: height
height: parent.height / 3 + 1
name: root.author.displayName
source: root.author.avatarUrl
color: root.author.color
}
Kirigami.Icon {
id: headingIcon
source: "go-up-symbolic"
color: parent.color
visible: !isNaN(root.heading) && root.isLive
anchors.bottom: mainIcon.top
anchors.horizontalCenter: mainIcon.horizontalCenter
transform: Rotation {
origin.x: headingIcon.width / 2
origin.y: headingIcon.height + mainIcon.height / 2
angle: root.heading
}
}
}
}

View File

@@ -0,0 +1,72 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtLocation
import QtPositioning
import org.kde.kirigami as Kirigami
import org.kde.neochat
Kirigami.Page {
id: root
required property var room
title: i18nc("Locations on a map", "Locations")
padding: 0
MapView {
id: mapView
anchors.fill: parent
map.plugin: OsmLocationPlugin.plugin
visible: mapView.map.mapItems.length !== 0
map.center: {
let c = LocationHelper.center(LocationHelper.unite(locationsModel.boundingBox, liveLocationsModel.boundingBox));
return QtPositioning.coordinate(c.y, c.x);
}
map.zoomLevel: {
const zoom = LocationHelper.zoomToFit(LocationHelper.unite(locationsModel.boundingBox, liveLocationsModel.boundingBox), mapView.width, mapView.height)
return Math.min(Math.max(zoom, map.minimumZoomLevel), map.maximumZoomLevel);
}
MapItemView {
Component.onCompleted: mapView.map.addMapItemView(this)
anchors.fill: parent
model: LocationsModel {
id: locationsModel
room: root.room
}
delegate: LocationMapItem {
isLive: false
heading: NaN
}
}
MapItemView {
Component.onCompleted: mapView.map.addMapItemView(this)
anchors.fill: parent
model: LiveLocationsModel {
id: liveLocationsModel
room: root.room
}
delegate: LocationMapItem {}
}
Connections {
target: mapView.map
function onCopyrightLinkActivated(link: string) {
Qt.openUrlExternally(link);
}
}
}
Kirigami.PlaceholderMessage {
text: i18n("There are no locations shared in this room.")
visible: mapView.map.mapItems.length === 0
anchors.centerIn: parent
}
}

362
src/app/qml/Main.qml Normal file
View File

@@ -0,0 +1,362 @@
// SPDX-FileCopyrightText: 2018-2020 Black Hat <bhat@encom.eu.org>
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: GPL-3.0-only
import QtQuick
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
import org.kde.config as KConfig
import org.kde.neochat
import org.kde.neochat.login
import org.kde.neochat.settings
Kirigami.ApplicationWindow {
id: root
property NeoChatConnection connection: Controller.activeConnection
readonly property HoverLinkIndicator hoverLinkIndicator: linkIndicator
property bool initialized: false
title: {
if (NeoChatConfig.windowTitleFocus) {
return activeFocusItem + " " + (activeFocusItem ? activeFocusItem.Accessible.name : "");
} else if (RoomManager.currentRoom) {
return RoomManager.currentRoom.displayName;
} else {
return Application.displayName;
}
}
minimumWidth: Kirigami.Units.gridUnit * 20
minimumHeight: Kirigami.Units.gridUnit * 15
visible: false // Will be overridden in Component.onCompleted
wideScreen: width > Kirigami.Units.gridUnit * 65
pageStack {
initialPage: WelcomePage {
showExisting: true
onConnectionChosen: root.load()
}
globalToolBar.canContainHandles: true
globalToolBar {
style: Kirigami.ApplicationHeaderStyle.ToolBar
showNavigationButtons: pageStack.currentIndex > 0 || pageStack.layers.depth > 1 ? Kirigami.ApplicationHeaderStyle.ShowBackButton : 0
}
}
onConnectionChanged: {
CustomEmojiModel.connection = root.connection;
SpaceHierarchyCache.connection = root.connection;
NeoChatSettingsView.connection = root.connection;
if (ShareHandler.text && root.connection) {
root.handleShare();
}
}
Connections {
target: LoginHelper
function onLoaded() {
root.load();
}
}
Connections {
target: Registration
function onLoaded() {
root.load();
}
}
Connections {
target: root.quitAction
function onTriggered() {
Qt.quit();
}
}
Loader {
active: Kirigami.Settings.hasPlatformMenuBar && !Kirigami.Settings.isMobile
sourceComponent: Qt.createComponent("org.kde.neochat", "GlobalMenu")
onActiveChanged: if (active) {
item.connection = root.connection;
}
}
KConfig.WindowStateSaver {
configGroupName: "MainWindow"
}
QuickSwitcher {
id: quickSwitcher
connection: root.connection
}
Connections {
target: RoomManager
function onCurrentRoomChanged() {
if (RoomManager.currentRoom && pageStack.depth <= 1 && root.initialized && Kirigami.Settings.isMobile) {
let roomPage = pageStack.layers.push(Qt.createComponent('org.kde.neochat', 'RoomPage'), {
connection: root.connection
});
roomPage.backRequested.connect(event => {
RoomManager.clearCurrentRoom();
});
}
}
function onAskJoinRoom(room) {
Qt.createComponent("org.kde.neochat", "JoinRoomDialog").createObject(root, {
room: room,
connection: root.connection
}).open();
}
function onShowUserDetail(user, room) {
root.showUserDetail(user, room);
}
function goToEvent(event) {
if (event.length > 0) {
roomItem.goToEvent(event);
}
roomItem.forceActiveFocus();
}
function onAskDirectChatConfirmation(user) {
Qt.createComponent("org.kde.neochat", "AskDirectChatConfirmation").createObject(this, {
user: user
}).open();
}
function onExternalUrl(url) {
let dialog = Qt.createComponent("org.kde.neochat", "ConfirmUrlDialog").createObject(this);
dialog.link = url;
dialog.open();
}
}
function pushReplaceLayer(page, args) {
if (pageStack.layers.depth === 2) {
pageStack.layers.replace(page, args);
} else {
pageStack.layers.push(page, args);
}
}
function openRoomDrawer() {
pageStack.push(Qt.createComponent('org.kde.neochat', 'RoomDrawerPage'), {
connection: root.connection
});
}
contextDrawer: RoomDrawer {
id: contextDrawer
// This is a memory for all user initiated actions on the drawer, i.e. clicking the button
// It is used to ensure that user choice is remembered when changing pages and expanding and contracting the window width
property bool drawerUserState: NeoChatConfig.autoRoomInfoDrawer
connection: root.connection
handleClosedIcon.source: "documentinfo-symbolic"
handleClosedToolTip: i18nc("@action:button", "Show Room Information")
// Default icon is fine, only need to override the tooltip text
handleOpenToolTip: i18nc("@action:button", "Close Room Information Drawer")
// Connect to the onClicked function of the RoomDrawer handle button
Connections {
target: contextDrawer.handle.children[0]
function onClicked() {
contextDrawer.drawerUserState = contextDrawer.drawerOpen;
}
}
modal: (!root.wideScreen || !enabled)
onEnabledChanged: drawerOpen = enabled && !modal
onModalChanged: {
if (NeoChatConfig.autoRoomInfoDrawer) {
drawerOpen = !modal && drawerUserState;
dim = false;
}
}
enabled: RoomManager.hasOpenRoom && pageStack.layers.depth < 2 && pageStack.depth < 3 && (pageStack.visibleItems.length > 1 || pageStack.currentIndex > 0) && !Kirigami.Settings.isMobile && root.pageStack.wideMode
handleVisible: enabled
}
Component.onCompleted: {
CustomEmojiModel.connection = root.connection;
SpaceHierarchyCache.connection = root.connection;
RoomSettingsView.window = root;
NeoChatSettingsView.window = root;
NeoChatSettingsView.connection = root.connection;
WindowController.setBlur(pageStack, NeoChatConfig.blur && !NeoChatConfig.compactLayout);
TextToSpeechWrapper.warmUp();
if (ShareHandler.text && root.connection) {
root.handleShare()
}
const hasSystemTray = Controller.supportSystemTray && NeoChatConfig.systemTray;
if (Kirigami.Settings.isMobile || !(hasSystemTray && NeoChatConfig.minimizeToSystemTrayOnStartup)) {
visible = true;
}
}
Connections {
target: NeoChatConfig
function onBlurChanged() {
WindowController.setBlur(pageStack, NeoChatConfig.blur && !NeoChatConfig.compactLayout);
}
function onCompactLayoutChanged() {
WindowController.setBlur(pageStack, NeoChatConfig.blur && !NeoChatConfig.compactLayout);
}
}
// blur effect
color: NeoChatConfig.blur && !NeoChatConfig.compactLayout ? "transparent" : Kirigami.Theme.backgroundColor
// we need to apply the translucency effect separately on top of the color
background: Rectangle {
color: NeoChatConfig.blur && !NeoChatConfig.compactLayout ? Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 1 - NeoChatConfig.transparency) : "transparent"
}
Component {
id: roomListComponent
RoomListPage {
id: roomList
onSearch: quickSwitcher.open()
connection: root.connection
Shortcut {
sequences: ["Ctrl+PgUp", "Ctrl+Backtab", "Alt+Up"]
onActivated: {
roomList.goToPreviousRoom();
}
}
Shortcut {
sequences: ["Ctrl+PgDown", "Ctrl+Tab", "Alt+Down"]
onActivated: {
roomList.goToNextRoom();
}
}
Shortcut {
sequence: "Alt+Shift+Up"
onActivated: {
roomList.goToPreviousUnreadRoom();
}
}
Shortcut {
sequence: "Alt+Shift+Down"
onActivated: {
roomList.goToNextUnreadRoom();
}
}
}
}
Connections {
target: AccountRegistry
function onRowsRemoved() {
if (AccountRegistry.rowCount() === 0) {
pageStack.clear();
pageStack.push(Qt.createComponent('org.kde.neochat.login', 'WelcomePage'));
}
}
}
Connections {
target: Controller
function onErrorOccured(error) {
showPassiveNotification(error, "short");
}
}
Connections {
target: root.connection
function onNewKeyVerificationSession(session) {
root.pageStack.pushDialogLayer(Qt.createComponent("org.kde.neochat", "KeyVerificationDialog"), {
session: session
}, {
title: i18nc("@title:window", "Session Verification")
});
}
function onUserConsentRequired(url) {
Qt.createComponent("org.kde.neochat", "ConsentDialog").createObject(this, {
url: url
}).open();
}
}
HoverLinkIndicator {
id: linkIndicator
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
rightMargin: Kirigami.Units.largeSpacing
}
}
Shortcut {
sequence: "Ctrl+Shift+,"
onActivated: {
NeoChatSettingsView.open();
}
}
Connections {
target: ShareHandler
function onTextChanged(): void {
if (root.connection && ShareHandler.text.length > 0) {
root.handleShare();
}
}
}
function handleShare(): void {
const dialog = applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ChooseRoomDialog'), {
connection: root.connection
}, {
title: i18nc("@title", "Share"),
width: Kirigami.Units.gridUnit * 25
})
dialog.chosen.connect(function(targetRoomId) {
RoomManager.resolveResource(targetRoomId)
ShareHandler.room = targetRoomId
dialog.closeDialog()
})
}
function showUserDetail(user, room) {
const dialog = Qt.createComponent("org.kde.neochat", "UserDetailDialog").createObject(root, {
room: room,
user: user,
connection: root.connection,
});
dialog.parent = QmlUtils.focusedWindowItem(); // Kirigami Dialogs overwrite the parent, so we need to set it again
dialog.open();
}
function load() {
pageStack.replace(roomListComponent);
RoomManager.loadInitialRoom();
if (!Kirigami.Settings.isMobile) {
let roomPage = pageStack.push(Qt.createComponent('org.kde.neochat', 'RoomPage'), {
connection: root.connection
});
roomPage.forceActiveFocus();
}
initialized = true;
}
}

View File

@@ -0,0 +1,113 @@
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Window
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.neochat
Kirigami.Dialog {
id: root
/**
* @brief The connection for the current user.
*/
required property NeoChatConnection connection
/**
* @brief Signal emitted when a valid room id or alias is entered.
*/
signal roomSelected(string roomId, string displayName, url avatarUrl, string alias, string topic, int memberCount, bool isJoined)
title: i18nc("@title", "Manually Enter a Room")
width: Math.min(root.Window.window.width, Kirigami.Units.gridUnit * 24)
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
standardButtons: Kirigami.Dialog.Cancel
customFooterActions: [
Kirigami.Action {
enabled: roomIdAliasText.isValidText
text: i18n("OK")
icon.name: "dialog-ok"
onTriggered: {
// We don't necessarily have all the info so fill out the best we can.
let roomId = roomIdAliasText.isAlias() ? "" : roomIdAliasText.text;
let displayName = "";
let avatarUrl = "";
let alias = roomIdAliasText.isAlias() ? roomIdAliasText.text : "";
let topic = "";
let memberCount = -1;
let isJoined = false;
if (roomIdAliasText.room) {
roomId = roomIdAliasText.room.id;
displayName = roomIdAliasText.room.displayName;
avatarUrl = roomIdAliasText.room.avatarUrl.toString().length > 0 ? connection.makeMediaUrl(roomIdAliasText.room.avatarUrl) : "";
alias = roomIdAliasText.room.canonicalAlias;
topic = roomIdAliasText.room.topic;
memberCount = roomIdAliasText.room.joinedCount;
isJoined = true;
}
root.roomSelected(roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined);
root.close();
}
}
]
contentItem: ColumnLayout {
spacing: 0
FormCard.FormTextFieldDelegate {
id: roomIdAliasText
property bool isValidText: text.match(/(#|!)(.+):(.+)/g)
property bool correctStart: text.startsWith("#") || text.startsWith("!")
property NeoChatRoom room: {
if (!acceptableInput) {
return null;
}
if (isAlias()) {
return root.connection.roomByAlias(text);
} else {
return root.connection.room(text);
}
}
label: i18n("Room ID or Alias:")
statusMessage: {
if (text.length > 0 && !correctStart) {
return i18n("Must start with # for an alias or ! for an ID");
}
if (timer.running) {
return "";
}
if (text.length > 0 && !isValidText) {
return i18n("The input is not a valid room ID or alias");
}
return correctStart ? "" : i18n("Must start with # for an alias or ! for an ID");
}
status: text.length > 0 ? Kirigami.MessageType.Error : Kirigami.MessageType.Information
onTextEdited: timer.restart()
function isAlias() {
return roomIdAliasText.text.startsWith("#");
}
Timer {
id: timer
interval: 1000
}
}
}
onVisibleChanged: {
roomIdAliasText.forceActiveFocus();
timer.restart();
}
}

View File

@@ -0,0 +1,82 @@
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.neochat
Kirigami.Dialog {
id: root
/**
* @brief The connection for the current user.
*/
required property NeoChatConnection connection
/**
* @brief Thrown when a user is selected.
*/
signal userSelected
title: i18nc("@title", "User ID")
width: Math.min(QQC2.ApplicationWindow.window.width, Kirigami.Units.gridUnit * 24)
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
standardButtons: Kirigami.Dialog.Cancel
customFooterActions: [
Kirigami.Action {
enabled: userIdText.isValidText
text: i18n("OK")
icon.name: "dialog-ok"
onTriggered: {
root.connection.requestDirectChat(userIdText.text);
root.accept();
}
}
]
contentItem: ColumnLayout {
spacing: 0
FormCard.FormTextFieldDelegate {
id: userIdText
property bool isValidText: text.match(/@(.+):(.+)/g)
property bool correctStart: text.startsWith("@")
label: i18n("User ID:")
statusMessage: {
if (text.length > 0 && !correctStart) {
return i18n("User IDs Must start with @");
}
if (timer.running) {
return "";
}
if (text.length > 0 && !isValidText) {
return i18n("The input is not a valid user ID");
}
return correctStart ? "" : i18n("User IDs Must start with @");
}
status: text.length > 0 ? Kirigami.MessageType.Error : Kirigami.MessageType.Information
onTextEdited: timer.restart()
Timer {
id: timer
interval: 1000
}
}
}
onVisibleChanged: {
userIdText.forceActiveFocus();
timer.restart();
}
}

View File

@@ -0,0 +1,138 @@
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
// SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-3.0-only
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.syntaxhighlighting
import org.kde.neochat
Kirigami.Page {
id: root
property var model
property NeoChatRoom room
property string type
property string stateKey
property bool allowEdit: false
property string contentJson: model.stateEventContentJson(root.type, root.stateKey)
property string sourceText: model.stateEventJson(root.type, root.stateKey)
topPadding: 0
leftPadding: 0
rightPadding: 0
bottomPadding: 0
Connections {
enabled: root.model
target: root.room
function onChanged(): void {
root.contentJson = model.stateEventContentJson(root.type, root.stateKey);
root.sourceText = model.stateEventJson(root.type, root.stateKey);
}
}
title: i18n("Event Source")
actions: [
Kirigami.Action {
text: i18nc("@action As in 'edit the state of this room'", "Edit state")
icon.name: "document-edit"
visible: root.allowEdit
enabled: room.canSendState(root.type) && (!root.stateKey.startsWith("@") || root.stateKey === root.room.connection.localUserId) && root.type !== "m.room.create"
onTriggered: pageStack.pushDialogLayer(Qt.createComponent("org.kde.neochat", "EditStateDialog.qml"), {
room: root.room,
type: root.type,
stateKey: root.stateKey,
sourceText: root.contentJson,
}, {
title: i18nc("@title As in 'edit the state of this room'", "Edit State")
})
}
]
QQC2.ScrollView {
id: scrollView
anchors.fill: parent
contentWidth: availableWidth
// HACK: Hide unnecessary horizontal scrollbar (https://bugreports.qt.io/browse/QTBUG-83890)
QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff
QQC2.TextArea {
id: sourceTextArea
Layout.fillWidth: true
leftPadding: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing * 2
text: root.sourceText
readOnly: true
textFormat: TextEdit.PlainText
wrapMode: TextEdit.Wrap
// opt-out of whatever spell checker a styled TextArea might come with
Kirigami.SpellCheck.enabled: false
onWidthChanged: lineModel.resetModel()
onHeightChanged: lineModel.resetModel()
SyntaxHighlighter {
textEdit: sourceTextArea
definition: "JSON"
repository: Repository
}
ColumnLayout {
id: lineNumberColumn
anchors {
top: sourceTextArea.top
topMargin: sourceTextArea.topPadding
left: sourceTextArea.left
leftMargin: Kirigami.Units.smallSpacing
}
spacing: 0
Repeater {
id: repeater
model: LineModel {
id: lineModel
document: sourceTextArea.textDocument
}
delegate: QQC2.Label {
id: label
required property int index
required property int docLineHeight
Layout.fillWidth: true
Layout.preferredHeight: docLineHeight
topPadding: 1
horizontalAlignment: Text.AlignRight
text: index + 1
color: Kirigami.Theme.disabledTextColor
}
}
}
background: Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
color: Kirigami.Theme.backgroundColor
}
}
}
Kirigami.Separator {
anchors {
top: parent.top
bottom: parent.bottom
left: parent.left
leftMargin: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing
}
}
}

View File

@@ -0,0 +1,138 @@
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtCore as Core
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import QtQuick.Dialogs as Dialogs
import QtMultimedia
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.labs.components as Components
import org.kde.neochat
Components.AlbumMaximizeComponent {
id: root
/**
* @brief The current room that user is viewing.
*/
required property NeoChatRoom currentRoom
readonly property string currentEventId: model.data(model.index(content.currentIndex, 0), TimelineMessageModel.EventIdRole)
readonly property var currentAuthor: model.data(model.index(content.currentIndex, 0), TimelineMessageModel.AuthorRole)
readonly property var currentTime: model.data(model.index(content.currentIndex, 0), TimelineMessageModel.TimeRole)
readonly property var currentProgressInfo: model.data(model.index(content.currentIndex, 0), TimelineMessageModel.ProgressInfoRole)
onCurrentProgressInfoChanged: () => {
if (root.currentProgressInfo) {
root.downloadAction.progress = root.currentProgressInfo.progress / root.currentProgressInfo.total * 100.0;
} else {
root.downloadAction.progress = 0;
}
}
/**
* @brief Whether the delegate is part of a thread timeline.
*/
property bool isThread: false
downloadAction: Components.DownloadAction {
onTriggered: {
currentRoom.downloadFile(root.currentEventId, Core.StandardPaths.writableLocation(Core.StandardPaths.CacheLocation) + "/" + root.currentEventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(root.currentEventId));
}
}
playAction: Kirigami.Action {
onTriggered: {
MediaManager.startPlayback();
currentItem.play();
}
}
Connections {
target: MediaManager
function onPlaybackStarted() {
if (currentItem.playbackState === MediaPlayer.PlayingState) {
currentItem.pause();
}
}
}
Connections {
target: currentRoom
function onFileTransferProgress(id, progress, total) {
if (id == root.currentEventId) {
root.downloadAction.progress = progress / total * 100.0;
}
}
}
leading: RowLayout {
Components.Avatar {
id: userAvatar
implicitWidth: Kirigami.Units.iconSizes.medium
implicitHeight: Kirigami.Units.iconSizes.medium
name: root.currentAuthor.name ?? root.currentAuthor.displayName
source: root.currentAuthor.avatarUrl
color: root.currentAuthor.color
}
ColumnLayout {
spacing: 0
QQC2.Label {
id: userLabel
text: root.currentAuthor.name ?? root.currentAuthor.displayName
color: root.currentAuthor.color
font.weight: Font.Bold
elide: Text.ElideRight
}
QQC2.Label {
id: dateTimeLabel
text: root.currentTime.toLocaleString(Qt.locale(), Locale.ShortFormat)
color: Kirigami.Theme.disabledTextColor
elide: Text.ElideRight
}
}
}
onOpened: forceActiveFocus()
onItemRightClicked: RoomManager.viewEventMenu(root.currentEventId, root.currentRoom, root.currentAuthor)
onSaveItem: {
var dialog = saveAsDialog.createObject(QQC2.Overlay.overlay);
dialog.selectedFile = currentRoom.fileNameToDownload(root.currentEventId);
dialog.open();
}
Connections {
target: RoomManager
function onCloseFullScreen() {
root.close();
}
}
Component {
id: saveAsDialog
Dialogs.FileDialog {
fileMode: Dialogs.FileDialog.SaveFile
currentFolder: root.saveFolder
onAccepted: {
NeoChatConfig.lastSaveDirectory = currentFolder;
NeoChatConfig.save();
if (!selectedFile) {
return;
}
currentRoom.downloadFile(root.currentEventId, selectedFile);
}
}
}
}

View File

@@ -0,0 +1,156 @@
// SPDX-FileCopyrightText: 2025 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
import org.kde.kirigamiaddons.delegates as Delegates
import Quotient
import org.kde.neochat
Kirigami.Dialog {
id: root
required property NeoChatRoom room
standardButtons: Kirigami.Dialog.Cancel
customFooterActions: [
Kirigami.Action {
enabled: optionModel.allValuesSet && questionTextField.text.length > 0
text: i18nc("@action:button", "Send")
icon.name: "document-send"
onTriggered: {
root.room.postPoll(pollTypeCombo.currentValue, questionTextField.text, optionModel.values())
root.close()
}
}
]
width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24)
title: i18nc("@title: create new poll in the room", "Create Poll")
contentItem: ColumnLayout {
spacing: 0
FormCard.FormComboBoxDelegate {
id: pollTypeCombo
text: i18n("Poll type:")
currentIndex: 0
textRole: "text"
valueRole: "value"
model: [
{ value: PollKind.Disclosed, text: i18n("Open poll") },
{ value: PollKind.Undisclosed, text: i18n("Closed poll") }
]
}
FormCard.FormTextDelegate {
verticalPadding: 0
text: pollTypeCombo.currentValue == 0 ? i18n("Voters can see the result as soon as they have voted") : i18n("Results are revealed only after the poll has closed")
}
FormCard.FormTextFieldDelegate {
id: questionTextField
label: i18n("Question:")
}
Repeater {
id: optionRepeater
model: ListModel {
id: optionModel
readonly property bool allValuesSet: {
for( var i = 0; i < optionModel.rowCount(); i++ ) {
if (optionModel.get(i).optionText.length <= 0) {
return false;
}
}
return true;
}
ListElement {
optionText: ""
}
ListElement {
optionText: ""
}
function values() {
let textValues = []
for( var i = 0; i < optionModel.rowCount(); i++ ) {
textValues.push(optionModel.get(i).optionText);
}
return textValues;
}
}
delegate: FormCard.AbstractFormDelegate {
id: optionDelegate
required property int index
required property string optionText
contentItem: ColumnLayout {
QQC2.Label {
id: optionLabel
Layout.fillWidth: true
text: i18nc("As in first answer option to the poll", "Option %1:", optionDelegate.index + 1)
elide: Text.ElideRight
wrapMode: Text.Wrap
Accessible.ignored: true
}
RowLayout {
Layout.fillWidth: true
QQC2.TextField {
id: textField
Layout.fillWidth: true
Accessible.name: optionLabel.text
onTextChanged: {
optionModel.set(optionDelegate.index, {optionText: text})
optionModel.allValuesSetChanged()
}
placeholderText: i18n("Enter option")
}
QQC2.ToolButton {
display: QQC2.AbstractButton.IconOnly
action: Kirigami.Action {
id: removeOptionAction
text: i18nc("@action:button", "Remove option")
icon.name: "edit-delete-remove"
onTriggered: optionModel.remove(optionDelegate.index)
}
QQC2.ToolTip {
text: removeOptionAction.text
delay: Kirigami.Units.toolTipDelay
}
}
}
}
background: null
}
}
Delegates.RoundedItemDelegate {
Layout.fillWidth: true
horizontalPadding: Kirigami.Units.largeSpacing * 2
leftInset: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
rightInset: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
highlighted: true
icon.name: "list-add"
text: i18nc("@action:button", "Add option")
onClicked: optionModel.append({optionText: ""})
}
}
}

View File

@@ -0,0 +1,93 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigami.delegates as KD
import org.kde.kirigamiaddons.components as Components
import org.kde.neochat
Kirigami.ScrollablePage {
id: root
required property NeoChatConnection connection
title: i18nc("@title", "Notifications")
ListView {
id: listView
anchors.fill: parent
verticalLayoutDirection: ListView.BottomToTop
model: NotificationsModel {
id: notificationsModel
connection: root.connection
}
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
visible: listView.count === 0
text: notificationsModel.loading ? i18n("Loading…") : i18n("No Notifications")
}
footer: Kirigami.PlaceholderMessage {
width: parent.width
text: i18n("Loading…")
visible: notificationsModel.nextToken.length > 0 && listView.count > 0
}
delegate: QQC2.ItemDelegate {
width: parent?.width ?? 0
onClicked: RoomManager.resolveResource(model.uri)
contentItem: RowLayout {
spacing: Kirigami.Units.largeSpacing
Components.Avatar {
source: model.authorAvatar
name: model.authorName
implicitHeight: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
implicitWidth: implicitHeight
Layout.fillHeight: true
Layout.preferredWidth: height
}
ColumnLayout {
spacing: 0
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
QQC2.Label {
id: label
text: model.roomDisplayName
elide: Text.ElideRight
font.weight: Font.Normal
textFormat: Text.PlainText
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
}
QQC2.Label {
id: subtitle
text: model.text
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
opacity: root.hasNotifications ? 0.9 : 0.7
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
}
}
}
}
}
}

View File

@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Dialogs
FileDialog {
id: root
signal chosen(string path)
title: i18n("Select a File")
onAccepted: root.chosen(selectedFile)
}

View File

@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2021 Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: GPL-2.0-or-later
pragma Singleton
import QtQuick
import QtLocation
QtObject {
id: root
property string userAgent: Application.name + "/" + Application.version + " (kde-devel@kde.org)"
property var plugin: Plugin {
name: "osm"
PluginParameter {
name: "osm.useragent"
value: root.userAgent
}
PluginParameter {
name: "osm.mapping.providersrepository.address"
value: "https://autoconfig.kde.org/qtlocation/"
}
}
}

View File

@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick
import org.kde.kirigamiaddons.labs.components as Components
import org.kde.kirigami as Kirigami
import org.kde.prison
Components.AbstractMaximizeComponent {
id: root
required property string text
property color avatarColor
required property url avatarSource
onOpened: forceActiveFocus()
Shortcut {
sequences: [StandardKey.Cancel]
onActivated: root.close()
}
leading: Components.Avatar {
id: userAvatar
implicitWidth: Kirigami.Units.iconSizes.medium
implicitHeight: Kirigami.Units.iconSizes.medium
name: root.title
source: root.avatarSource
color: root.avatarColor
}
content: Item {
Keys.onEscapePressed: root.close()
Barcode {
barcodeType: Barcode.QRCode
content: root.text
height: Math.min(parent.height, Kirigami.Units.gridUnit * 20)
width: height
anchors.centerIn: parent
}
MouseArea {
id: closeArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onClicked: root.close()
}
}
}

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtMultimedia
import org.kde.kirigami as Kirigami
import org.kde.prison.scanner as Prison
import org.kde.neochat
Kirigami.Page {
id: root
title: i18nc("@title", "Scan a QR Code")
required property NeoChatConnection connection
padding: 0
Component.onCompleted: camera.start()
Connections {
target: root.QQC2.ApplicationWindow.window
function onClosing() {
root.destroy();
}
}
VideoOutput {
id: viewFinder
anchors.centerIn: parent
}
Prison.VideoScanner {
id: scanner
property string previousText: ""
formats: Prison.Format.QRCode | Prison.Format.Aztec
onResultChanged: {
if (result.text.length > 0 && result.text != scanner.previousText) {
RoomManager.resolveResource(result.text, "qr");
scanner.previousText = result.text;
}
root.closeDialog();
}
videoSink: viewFinder.videoSink
}
CaptureSession {
camera: Camera {
id: camera
}
imageCapture: ImageCapture {
id: imageCapture
}
videoOutput: viewFinder
}
}

View File

@@ -0,0 +1,136 @@
// SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
QQC2.Popup {
id: root
property var selectionStart
property var selectionEnd
signal formattingSelected(var format, int selectionStart, int selectionEnd)
padding: 1
contentItem: Flow {
QQC2.ToolButton {
icon.name: "format-text-bold"
text: i18n("Bold")
display: QQC2.AbstractButton.IconOnly
onClicked: {
const format = {
start: "**",
end: "**",
extra: ""
};
formattingSelected(format, selectionStart, selectionEnd);
root.close();
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.ToolButton {
icon.name: "format-text-italic"
text: i18n("Italic")
display: QQC2.AbstractButton.IconOnly
onClicked: {
const format = {
start: "*",
end: "*",
extra: ""
};
formattingSelected(format, selectionStart, selectionEnd);
root.close();
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.ToolButton {
icon.name: "format-text-strikethrough"
text: i18n("Strikethrough")
display: QQC2.AbstractButton.IconOnly
onClicked: {
const format = {
start: "<del>",
end: "</del>",
extra: ""
};
formattingSelected(format, selectionStart, selectionEnd);
root.close();
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.ToolButton {
icon.name: "format-text-code"
text: i18n("Code block")
display: QQC2.AbstractButton.IconOnly
onClicked: {
const format = {
start: "`",
end: "`",
extra: ""
};
formattingSelected(format, selectionStart, selectionEnd);
root.close();
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.ToolButton {
icon.name: "format-text-blockquote"
text: i18n("Quote")
display: QQC2.AbstractButton.IconOnly
onClicked: {
const format = {
start: selectionStart == 0 ? ">" : "\n>",
end: "\n\n",
extra: ""
};
formattingSelected(format, selectionStart, selectionEnd);
root.close();
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.ToolButton {
icon.name: "link"
text: i18n("Insert link")
display: QQC2.AbstractButton.IconOnly
onClicked: {
const format = {
start: "[",
end: "](",
extra: ")"
};
formattingSelected(format, selectionStart, selectionEnd);
root.close();
}
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
}
}

View File

@@ -0,0 +1,56 @@
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kitemmodels
import org.kde.neochat
Kirigami.SearchDialog {
id: root
required property NeoChatConnection connection
Shortcut {
sequence: "Ctrl+K"
onActivated: root.open()
}
onAccepted: if (currentItem) {
currentItem.clicked();
}
onTextChanged: RoomManager.sortFilterRoomListModel.filterText = text
model: RoomManager.sortFilterRoomListModel
emptyText: i18nc("Placeholder message", "No room found")
Kirigami.Action {
id: exploreRoomAction
text: i18nc("@action:button", "Explore rooms")
icon.name: "compass"
onTriggered: {
root.close()
let dialog = pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage'), {
connection: root.connection
}, {
title: i18nc("@title", "Explore Rooms")
});
dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
RoomManager.resolveResource(roomId.length > 0 ? roomId : alias, isJoined ? "" : "join");
});
}
}
Component.onCompleted: emptyHelpfulAction = exploreRoomAction
parent: QQC2.Overlay.overlay
delegate: RoomDelegate {
connection: root.connection
onClicked: root.close()
showConfigure: false
}
}

View File

@@ -0,0 +1,59 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.neochat
Kirigami.Page {
id: root
required property string placeholder
required property string actionText
required property string icon
signal accepted(reason: string)
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
QQC2.TextArea {
id: reason
placeholderText: root.placeholder
anchors.fill: parent
wrapMode: TextEdit.Wrap
background: Rectangle {
color: Kirigami.Theme.backgroundColor
}
}
footer: QQC2.ToolBar {
QQC2.DialogButtonBox {
anchors.fill: parent
Item {
Layout.fillWidth: true
}
QQC2.Button {
text: root.actionText
icon.name: root.icon
QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.AcceptRole
onClicked: {
root.accepted(reason.text);
root.closeDialog();
}
}
QQC2.Button {
text: i18nc("@action", "Cancel")
QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.RejectRole
onClicked: root.closeDialog()
}
}
}
}

View File

@@ -0,0 +1,70 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.kirigamiaddons.components
import org.kde.neochat
Kirigami.Dialog {
id: root
property var connection
parent: applicationWindow().overlay
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
title: i18nc("@title Join <name of a space>", "Join %1", SpaceHierarchyCache.recommendedSpaceDisplayName)
width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24)
contentItem: ColumnLayout {
FormCard.AbstractFormDelegate {
background: null
contentItem: RowLayout {
spacing: Kirigami.Units.largeSpacing
Avatar {
source: SpaceHierarchyCache.recommendedSpaceAvatar.toString().length > 0 ? root.connection.makeMediaUrl(SpaceHierarchyCache.recommendedSpaceAvatar) : 0
name: SpaceHierarchyCache.recommendedSpaceDisplayName
}
ColumnLayout {
Layout.fillWidth: true
Kirigami.Heading {
Layout.fillWidth: true
text: SpaceHierarchyCache.recommendedSpaceDisplayName
}
QQC2.Label {
Layout.fillWidth: true
text: SpaceHierarchyCache.recommendedSpaceDescription
}
}
}
}
FormCard.FormDelegateSeparator {}
FormCard.FormButtonDelegate {
text: i18nc("@action:button", "Join")
icon.name: "list-add-symbolic"
onClicked: {
SpaceHierarchyCache.recommendedSpaceHidden = true;
RoomManager.resolveResource(SpaceHierarchyCache.recommendedSpaceId, "join");
root.close();
}
}
FormCard.FormButtonDelegate {
icon.name: "mail-thread-ignored-symbolic"
text: i18nc("@action:button", "Ignore")
onClicked: {
SpaceHierarchyCache.recommendedSpaceHidden = true;
root.close();
}
}
}
}

View File

@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.neochat
Kirigami.Dialog {
id: root
required property NeoChatRoom parentRoom
required property string roomId
required property string displayName
required property string parentDisplayName
required property bool canSetParent
required property bool isDeclaredParent
title: i18nc("@title", "Remove Child")
width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24)
standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
onAccepted: parentRoom.removeChild(root.roomId, removeOfficalCheck.checked)
contentItem: ColumnLayout {
spacing: 0
FormCard.FormTextDelegate {
text: i18n("The child %1 will be removed from the space %2", root.displayName, root.parentDisplayName)
textItem.wrapMode: Text.Wrap
}
FormCard.FormCheckDelegate {
id: removeOfficalCheck
visible: root.isDeclaredParent
enabled: root.canSetParent
text: i18n("The current space is the official parent of this room, should this be cleared?")
checked: root.canSetParent
}
}
}

179
src/app/qml/RoomDrawer.qml Normal file
View File

@@ -0,0 +1,179 @@
// SPDX-FileCopyrightText: 2018-2019 Black Hat <bhat@encom.eu.org>
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: GPL-3.0-only
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kitemmodels
import org.kde.neochat
import org.kde.neochat.settings
Kirigami.OverlayDrawer {
id: root
readonly property NeoChatRoom room: RoomManager.currentRoom
required property NeoChatConnection connection
width: actualWidth
interactive: modal
readonly property int minWidth: Kirigami.Units.gridUnit * 15
readonly property int maxWidth: Kirigami.Units.gridUnit * 25
readonly property int defaultWidth: Kirigami.Units.gridUnit * 20
property int actualWidth: {
if (NeoChatConfig.roomDrawerWidth === -1) {
return Kirigami.Units.gridUnit * 20;
} else {
return NeoChatConfig.roomDrawerWidth;
}
}
onOpened: forceActiveFocus()
MouseArea {
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: undefined
width: 2
z: 500
cursorShape: !Kirigami.Settings.isMobile ? Qt.SplitHCursor : undefined
enabled: true
visible: true
onPressed: _lastX = mapToGlobal(mouseX, mouseY).x
onReleased: {
NeoChatConfig.roomDrawerWidth = root.actualWidth;
NeoChatConfig.save();
}
property real _lastX: -1
onPositionChanged: {
if (_lastX === -1) {
return;
}
if (Qt.application.layoutDirection === Qt.RightToLeft) {
root.actualWidth = Math.min(root.maxWidth, Math.max(root.minWidth, NeoChatConfig.roomDrawerWidth - _lastX + mapToGlobal(mouseX, mouseY).x));
} else {
root.actualWidth = Math.min(root.maxWidth, Math.max(root.minWidth, NeoChatConfig.roomDrawerWidth + _lastX - mapToGlobal(mouseX, mouseY).x));
}
}
}
enabled: true
edge: Qt.application.layoutDirection == Qt.RightToLeft ? Qt.LeftEdge : Qt.RightEdge
// If modal has been changed and the drawer is closed automatically then dim on popup open will have been switched off in main.qml so switch it back on after the animation completes.
// This is to avoid dim being active for a split second when the drawer is switched to modal which looks terrible.
onAnimatingChanged: if (dim === false)
dim = undefined
topPadding: 0
bottomPadding: 0
leftPadding: 0
rightPadding: 0
Kirigami.Theme.colorSet: Kirigami.Theme.View
contentItem: Loader {
id: loader
active: root.drawerOpen
sourceComponent: RowLayout {
spacing: 0
Kirigami.Separator {
Layout.fillHeight: true
visible: root.modal
}
ColumnLayout {
spacing: 0
Component.onCompleted: infoAction.toggle()
QQC2.ToolBar {
Layout.fillWidth: true
Layout.preferredHeight: pageStack.globalToolBar.preferredHeight
contentItem: RowLayout {
spacing: 0
Kirigami.Heading {
Layout.fillWidth: true
Layout.leftMargin: Kirigami.Units.largeSpacing
text: drawerItemLoader.item ? drawerItemLoader.item.title : ""
}
QQC2.ToolButton {
id: settingsButton
display: QQC2.AbstractButton.IconOnly
text: i18nc("@action:button", "Room settings")
icon.name: 'settings-configure-symbolic'
QQC2.ToolTip.text: text
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
QQC2.ToolTip.visible: hovered
onClicked: {
RoomSettingsView.openRoomSettings(root.room, RoomSettingsView.Room);
}
}
}
}
Loader {
id: drawerItemLoader
Layout.fillWidth: true
Layout.fillHeight: true
sourceComponent: roomInformation
}
Component {
id: roomInformation
RoomInformation {
room: root.room
connection: root.connection
}
}
Component {
id: roomMedia
RoomMedia {
currentRoom: root.room
connection: root.connection
}
}
Kirigami.NavigationTabBar {
id: navigationBar
Layout.fillWidth: true
visible: !root.room.isSpace
Kirigami.Theme.colorSet: Kirigami.Theme.Window
Kirigami.Theme.inherit: false
position: QQC2.ToolBar.Footer
actions: [
Kirigami.Action {
id: infoAction
text: i18n("Information")
icon.name: "documentinfo"
onTriggered: drawerItemLoader.sourceComponent = roomInformation
},
Kirigami.Action {
text: i18n("Media")
icon.name: "mail-attachment-symbollic"
onTriggered: drawerItemLoader.sourceComponent = roomMedia
}
]
}
}
}
}
}

View File

@@ -0,0 +1,110 @@
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kitemmodels
import org.kde.neochat
/**
* @brief Page for holding a room drawer component.
*
* This the companion component to RoomDrawer and is designed to be used on mobile
* where we want the room drawer to be pushed as a page as thin drawer doesn't
* look good.
*
* @sa RoomDrawer
*/
Kirigami.Page {
id: root
/**
* @brief The current room that user is viewing.
*/
readonly property NeoChatRoom room: RoomManager.currentRoom
required property NeoChatConnection connection
title: drawerItemLoader.item ? drawerItemLoader.item.title : ""
topPadding: 0
bottomPadding: 0
leftPadding: 0
rightPadding: 0
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
Component.onCompleted: infoAction.toggle()
actions: [
Kirigami.Action {
displayHint: Kirigami.DisplayHint.IconOnly
text: i18nc("@action:button", "Room settings")
icon.name: 'settings-configure-symbolic'
onTriggered: {
RoomSettingsView.openRoomSettings(root.room, RoomSettingsView.Room);
}
}
]
Loader {
id: drawerItemLoader
width: parent.width
height: parent.height
sourceComponent: roomInformation
}
Component {
id: roomInformation
RoomInformation {
room: root.room
connection: root.connection
}
}
Component {
id: roomMedia
RoomMedia {
currentRoom: root.room
connection: root.connection
}
}
footer: Kirigami.NavigationTabBar {
id: navigationBar
visible: !root.room.isSpace
Kirigami.Theme.colorSet: Kirigami.Theme.Window
Kirigami.Theme.inherit: false
actions: [
Kirigami.Action {
id: infoAction
text: i18n("Information")
icon.name: "documentinfo"
onTriggered: drawerItemLoader.sourceComponent = roomInformation
},
Kirigami.Action {
text: i18n("Media")
icon.name: "mail-attachment-symbollic"
onTriggered: drawerItemLoader.sourceComponent = roomMedia
}
]
}
Connections {
target: applicationWindow().pageStack
onWideModeChanged: {
if (applicationWindow().pageStack.wideMode) {
applicationWindow().pageStack.pop();
}
}
}
onBackRequested: event => {
event.accepted = true;
applicationWindow().pageStack.pop();
}
}

View File

@@ -0,0 +1,298 @@
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
import org.kde.kitemmodels
import org.kde.neochat
/**
* @brief Component for visualising the room information.
*
* The component has a header section which changes between group rooms and direct
* chats with information like the avatar and topic. Followed by the allowed actions
* and finally a user list.
*
* @note This component is only the contents, it will need to be placed in either
* a drawer (desktop) or page (mobile) to be used.
*
* @sa RoomDrawer, RoomDrawerPage
*/
QQC2.ScrollView {
id: root
/**
* @brief The current room that user is viewing.
*/
required property NeoChatRoom room
required property NeoChatConnection connection
/**
* @brief The title that should be displayed for this component if available.
*/
readonly property string title: root.room.isSpace ? i18nc("@action:title", "Space Members") : i18nc("@action:title", "Room Information")
// HACK: Hide unnecessary horizontal scrollbar (https://bugreports.qt.io/browse/QTBUG-83890)
QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff
ListView {
id: userList
header: ColumnLayout {
id: columnLayout
property alias userListSearchField: userListSearchField
spacing: 0
width: ListView.view ? ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin : 0
Loader {
active: true
Layout.fillWidth: true
Layout.topMargin: Kirigami.Units.smallSpacing
visible: !root.room.isSpace
sourceComponent: root.room.isDirectChat() ? directChatDrawerHeader : groupChatDrawerHeader
onItemChanged: if (item) {
userList.positionViewAtBeginning();
}
}
Kirigami.ListSectionHeader {
visible: !root.room.isSpace
label: i18nc("Room actions", "Actions")
activeFocusOnTab: false
Layout.fillWidth: true
}
Delegates.RoundedItemDelegate {
id: searchButton
visible: !root.room.isSpace
icon.name: "search"
text: i18n("Search in this room")
activeFocusOnTab: true
Layout.fillWidth: true
onClicked: {
pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'RoomSearchPage'), {
room: root.room
}, {
title: i18nc("@action:title", "Search")
});
}
}
Delegates.RoundedItemDelegate {
visible: root.room.isDirectChat()
icon.name: "security-low-symbolic"
text: i18nc("@action:button", "Verify user")
onClicked: root.room.startVerification()
Layout.fillWidth: true
}
Delegates.RoundedItemDelegate {
id: favouriteButton
visible: !root.room.isSpace
icon.name: root.room && root.room.isFavourite ? "rating" : "rating-unrated"
text: root.room && root.room.isFavourite ? i18n("Remove room from favorites") : i18n("Favorite this room")
onClicked: root.room.isFavourite ? root.room.removeTag("m.favourite") : root.room.addTag("m.favourite", 1.0)
activeFocusOnTab: true
Layout.fillWidth: true
}
Delegates.RoundedItemDelegate {
id: locationsButton
visible: !root.room.isSpace
icon.name: "map-flat"
text: i18n("Show locations for this room")
activeFocusOnTab: true
onClicked: pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'LocationsPage'), {
room: root.room
}, {
title: i18nc("Locations on a map", "Locations")
})
Layout.fillWidth: true
}
Delegates.RoundedItemDelegate {
id: pinnedMessagesButton
visible: !root.room.isSpace
icon.name: "pin-symbolic"
text: i18nc("@action:button", "Pinned messages")
activeFocusOnTab: true
Layout.fillWidth: true
onClicked: {
pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'RoomPinnedMessagesPage'), {
room: root.room
}, {
title: i18nc("@title", "Pinned Messages")
});
}
}
Delegates.RoundedItemDelegate {
id: leaveButton
icon.name: "arrow-left-symbolic"
text: root.room.isSpace ? i18nc("@action:button", "Leave this space") : i18nc("@action:button", "Leave this room")
activeFocusOnTab: true
Layout.fillWidth: true
onClicked: {
Qt.createComponent('org.kde.neochat', 'ConfirmLeaveDialog').createObject(root.QQC2.ApplicationWindow.window, {
room: root.room
}).open();
}
}
Kirigami.ListSectionHeader {
label: i18n("Members")
activeFocusOnTab: false
spacing: 0
visible: !root.room.isDirectChat()
Layout.fillWidth: true
QQC2.ToolButton {
visible: root.room.canSendState("invite")
icon.name: "list-add-user"
onClicked: {
applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'InviteUserPage'), {
room: root.room
}, {
title: i18nc("@title", "Invite a User")
});
}
QQC2.ToolTip.text: i18n("Invite user to room")
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.Label {
Layout.alignment: Qt.AlignRight
text: root.room ? i18np("%1 member", "%1 members", root.room.joinedCount) : i18n("No member count")
}
}
Kirigami.SearchField {
id: userListSearchField
visible: !root.room.isDirectChat()
onVisibleChanged: if (visible) {
forceActiveFocus();
}
Layout.fillWidth: true
Layout.leftMargin: Kirigami.Units.largeSpacing
Layout.rightMargin: Kirigami.Units.largeSpacing
Layout.bottomMargin: Kirigami.Units.smallSpacing
focusSequence: "Ctrl+Shift+F"
onAccepted: userFilterModel.filterText = text
}
}
model: root.room.isDirectChat() ? 0 : userFilterModel
UserFilterModel {
id: userFilterModel
sourceModel: RoomManager.userListModel
allowEmpty: true
}
clip: true
focus: true
section.property: "powerLevelString"
section.delegate: Kirigami.ListSectionHeader {
required property string section
width: ListView.view.width
text: section
}
delegate: Delegates.RoundedItemDelegate {
id: userDelegate
required property int index
required property string name
required property string userId
required property url avatar
required property int powerLevel
required property string powerLevelString
implicitHeight: Kirigami.Units.gridUnit * 2
text: name
KeyNavigation.tab: navigationBar.tabGroup.checkedButton
KeyNavigation.backtab: index === 0 ? userList.headerItem.userListSearchField : null
onClicked: {
RoomManager.resolveResource(userDelegate.userId, "mention");
}
contentItem: RowLayout {
KirigamiComponents.Avatar {
implicitWidth: height
sourceSize {
height: Kirigami.Units.gridUnit + Kirigami.Units.smallSpacing * 2.5
width: Kirigami.Units.gridUnit + Kirigami.Units.smallSpacing * 2.5
}
source: userDelegate.avatar
name: userDelegate.userId
Layout.fillHeight: true
}
QQC2.Label {
text: userDelegate.name
textFormat: Text.PlainText
elide: Text.ElideRight
Layout.fillWidth: true
}
}
}
}
Component {
id: groupChatDrawerHeader
GroupChatDrawerHeader {
room: root.room
}
}
Component {
id: directChatDrawerHeader
DirectChatDrawerHeader {
room: root.room
}
}
onRoomChanged: {
if (userList.headerItem) {
userList.headerItem.userListSearchField.text = "";
}
userList.currentIndex = -1;
}
}

69
src/app/qml/RoomMedia.qml Normal file
View File

@@ -0,0 +1,69 @@
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import Qt.labs.qmlmodels
import org.kde.neochat
import org.kde.neochat.timeline
/**
* @brief Component for visualising the loaded media items in the room.
*
* The component is a simple list of media delegates (videos or images) with the
* ability to open them in the mamimize component.
*
* @note This component is only the contents, it will need to be placed in either
* a drawer (desktop) or page (mobile) to be used.
*
* @sa RoomDrawer, RoomDrawerPage
*/
QQC2.ScrollView {
id: root
/**
* @brief The title that should be displayed for this component if available.
*/
readonly property string title: i18nc("@action:title", "Room Media")
/**
* @brief The current room that user is viewing.
*/
required property NeoChatRoom currentRoom
required property NeoChatConnection connection
// HACK: Hide unnecessary horizontal scrollbar (https://bugreports.qt.io/browse/QTBUG-83890)
QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff
ListView {
clip: true
verticalLayoutDirection: ListView.BottomToTop
model: RoomManager.mediaMessageFilterModel
delegate: DelegateChooser {
role: "type"
DelegateChoice {
roleValue: MediaMessageFilterModel.Image
delegate: MessageDelegate {
alwaysFillWidth: true
cardBackground: false
room: root.currentRoom
}
}
DelegateChoice {
roleValue: MediaMessageFilterModel.Video
delegate: MessageDelegate {
alwaysFillWidth: true
cardBackground: false
room: root.currentRoom
}
}
}
}
}

315
src/app/qml/RoomPage.qml Normal file
View File

@@ -0,0 +1,315 @@
// SPDX-FileCopyrightText: 2018-2020 Black Hat <bhat@encom.eu.org>
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: GPL-3.0-only
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import QtQuick.Window
import org.kde.kirigami as Kirigami
import org.kde.kitemmodels
import org.kde.neochat
import org.kde.neochat.chatbar
Kirigami.Page {
id: root
/// Not readonly because of the separate window view.
property NeoChatRoom currentRoom: RoomManager.currentRoom
required property NeoChatConnection connection
/**
* @brief The TimelineModel to use.
*
* Required so that new events can be requested when the end of the current
* local timeline is reached.
*
* @note For loading a room in a different window, override this with a new
* TimelineModel set with the room to be shown.
*
* @sa TimelineModel
*/
property TimelineModel timelineModel: RoomManager.timelineModel
/**
* @brief The MessageFilterModel to use.
*
* This model has the filtered list of events that should be shown in the timeline.
*
* @note For loading a room in a different window, override this with a new
* MessageFilterModel with the new TimelineModel as the source model.
*
* @sa TimelineModel, MessageFilterModel
*/
property MessageFilterModel messageFilterModel: RoomManager.messageFilterModel
/**
* @brief The MediaMessageFilterModel to use.
*
* This model has the filtered list of media events that should be shown in
* the timeline.
*
* @note For loading a room in a different window, override this with a new
* MediaMessageFilterModel with the new MessageFilterModel as the source model.
*
* @sa TimelineModel, MessageFilterModel
*/
property MediaMessageFilterModel mediaMessageFilterModel: RoomManager.mediaMessageFilterModel
property bool loading: !root.currentRoom || (root.currentRoom.timelineSize === 0 && !root.currentRoom.allHistoryLoaded)
/// Disable cancel shortcut. Used by the separate window since it provides its own cancel implementation.
property bool disableCancelShortcut: false
title: root.currentRoom ? root.currentRoom.displayName : ""
focus: true
padding: 0
actions: [
Kirigami.Action {
visible: Kirigami.Settings.isMobile || !applicationWindow().pageStack.wideMode
icon.name: "view-right-new"
onTriggered: applicationWindow().openRoomDrawer()
}
]
KeyNavigation.left: pageStack.get(0)
onCurrentRoomChanged: {
banner.visible = false;
if (!Kirigami.Settings.isMobile && chatBarLoader.item) {
chatBarLoader.item.forceActiveFocus();
}
}
Connections {
target: root.connection
function onIsOnlineChanged() {
if (!root.connection.isOnline) {
banner.text = i18n("NeoChat is offline. Please check your network connection.");
banner.visible = true;
banner.type = Kirigami.MessageType.Error;
} else {
banner.visible = false;
}
}
}
header: Kirigami.InlineMessage {
id: banner
showCloseButton: true
visible: false
position: Kirigami.InlineMessage.Position.Header
}
Loader {
id: timelineViewLoader
anchors.fill: parent
active: root.currentRoom && !root.currentRoom.isInvite && !root.loading && !root.currentRoom.isSpace
sourceComponent: TimelineView {
id: timelineView
currentRoom: root.currentRoom
page: root
timelineModel: root.timelineModel
messageFilterModel: root.messageFilterModel
onFocusChatBar: {
if (chatBarLoader.item) {
chatBarLoader.item.forceActiveFocus();
}
}
}
}
Loader {
id: invitationLoader
active: root.currentRoom && root.currentRoom.isInvite
anchors.centerIn: parent
sourceComponent: InvitationView {
currentRoom: root.currentRoom
anchors.centerIn: parent
}
}
Loader {
id: spaceLoader
active: root.currentRoom && root.currentRoom.isSpace
anchors.fill: parent
sourceComponent: SpaceHomePage {}
}
Loader {
active: !RoomManager.currentRoom
anchors.centerIn: parent
sourceComponent: Kirigami.PlaceholderMessage {
icon.name: "org.kde.neochat"
text: i18n("Welcome to NeoChat")
explanation: i18n("Select or join a room to get started")
}
}
Loader {
active: root.loading && !invitationLoader.active && RoomManager.currentRoom && !spaceLoader.active
anchors.centerIn: parent
sourceComponent: Kirigami.LoadingPlaceholder {
anchors.centerIn: parent
}
}
background: Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
color: NeoChatConfig.compactLayout ? Kirigami.Theme.backgroundColor : "transparent"
}
footer: Loader {
id: chatBarLoader
height: active ? item.implicitHeight : 0
active: timelineViewLoader.active && !root.currentRoom.readOnly
sourceComponent: ChatBar {
id: chatBar
width: parent.width
currentRoom: root.currentRoom
connection: root.connection
onMessageSent: {
if (!timelineViewLoader.item.atYEnd) {
timelineViewLoader.item.goToLastMessage();
}
}
}
}
Connections {
target: RoomManager
function onCurrentRoomChanged() {
if (root.currentRoom && root.currentRoom.isInvite) {
Controller.clearInvitationNotification(root.currentRoom.id);
}
}
function onGoToEvent(eventId) {
(timelineViewLoader.item as TimelineView).goToEvent(eventId);
}
}
Shortcut {
sequence: StandardKey.Cancel
onActivated: {
if (!timelineViewLoader.item.atYEnd || !root.currentRoom.partiallyReadStats.empty()) {
timelineViewLoader.item.goToLastMessage();
root.currentRoom.markAllMessagesAsRead();
} else {
applicationWindow().pageStack.get(0).forceActiveFocus();
}
}
enabled: !root.disableCancelShortcut
}
Connections {
target: root.connection
function onJoinedRoom(room, invited) {
if (root.currentRoom.id === invited.id) {
RoomManager.resolveResource(room.id);
}
}
}
Keys.onPressed: event => {
if (event.key === Qt.Key_PageUp) {
event.accepted = true;
timelineViewLoader.item.pageUp();
} else if (event.key === Qt.Key_PageDown) {
event.accepted = true;
timelineViewLoader.item.pageDown();
}
}
Connections {
target: RoomManager
function onShowMessage(messageType, message) {
banner.text = message;
banner.type = messageType;
banner.visible = true;
}
function onShowEventSource(eventId) {
applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'MessageSourceSheet'), {
sourceText: root.currentRoom.getEventJsonSource(eventId)
}, {
title: i18n("Message Source"),
width: Kirigami.Units.gridUnit * 25
});
}
function onShowMessageMenu(eventId, author, messageComponentType, plainText, htmlText, selectedText, hoveredLink, isThread) {
const contextMenu = messageDelegateContextMenu.createObject(root, {
selectedText: selectedText,
hoveredLink: hoveredLink,
author: author,
eventId: eventId,
messageComponentType: messageComponentType,
plainText: plainText,
htmlText: htmlText,
});
contextMenu.popup();
}
function onShowFileMenu(eventId, author, messageComponentType, plainText, mimeType, progressInfo, isThread) {
const contextMenu = fileDelegateContextMenu.createObject(root, {
author: author,
eventId: eventId,
plainText: plainText,
mimeType: mimeType,
progressInfo: progressInfo,
});
contextMenu.popup();
}
function onShowMaximizedMedia(index) {
var popup = maximizeComponent.createObject(QQC2.Overlay.overlay, {
initialIndex: index
});
popup.closed.connect(() => {
timelineViewLoader.item.interactive = true;
popup.destroy();
});
popup.open();
}
function onShowMaximizedCode(author, time, codeText, language) {
let popup = Qt.createComponent('org.kde.neochat', 'CodeMaximizeComponent').createObject(QQC2.Overlay.overlay, {
author: author,
time: time,
codeText: codeText,
language: language
}).open();
}
}
Component {
id: messageDelegateContextMenu
MessageDelegateContextMenu {
connection: root.connection
}
}
Component {
id: fileDelegateContextMenu
FileDelegateContextMenu {
connection: root.connection
}
}
Component {
id: maximizeComponent
NeochatMaximizeComponent {
currentRoom: root.currentRoom
model: root.mediaMessageFilterModel
parent: root.QQC2.Overlay.overlay
}
}
}

View File

@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: 2025 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.neochat
import org.kde.neochat.timeline
/**
* @brief Component for showing the pinned messages in a room.
*/
Kirigami.ScrollablePage {
id: root
/**
* @brief The room to show the pinned messages for.
*/
required property NeoChatRoom room
title: i18nc("@title", "Pinned Messages")
Kirigami.Theme.colorSet: Kirigami.Theme.Window
Kirigami.Theme.inherit: false
ListView {
id: listView
spacing: 0
model: PinnedMessageModel {
id: pinModel
room: root.room
}
delegate: EventDelegate {
room: root.room
}
section.property: "section"
Kirigami.PlaceholderMessage {
icon.name: "pin-symbolic"
anchors.centerIn: parent
text: i18nc("@info:placeholder", "No Pinned Messages")
visible: listView.count === 0
}
Kirigami.LoadingPlaceholder {
anchors.centerIn: parent
visible: listView.count === 0 && pinModel.loading
}
Keys.onUpPressed: {
if (listView.currentIndex > 0) {
listView.decrementCurrentIndex();
} else {
listView.currentIndex = -1; // This is so the list view doesn't appear to have two selected items
listView.headerItem.forceActiveFocus(Qt.TabFocusReason);
}
}
}
}

View File

@@ -0,0 +1,42 @@
// SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import org.kde.neochat
import org.kde.neochat.timeline
/**
* @brief Component for finding messages in a room.
*
* This component is based on a SearchPage and allows the user to enter a search
* term into the input field and then search the room for messages with text that
* matches the input.
*
* @sa SearchPage
*/
SearchPage {
id: root
/**
* @brief The room the search is being performed in.
*/
required property NeoChatRoom room
title: i18nc("@action:title", "Search Messages")
model: SearchModel {
id: searchModel
room: root.room
}
modelDelegate: EventDelegate {
room: root.room
}
searchFieldPlaceholder: i18n("Find messages…")
noSearchPlaceholderMessage: i18n("Enter text to start searching")
noResultPlaceholderMessage: i18n("No messages found")
listVerticalLayoutDirection: ListView.BottomToTop
}

211
src/app/qml/SearchPage.qml Normal file
View File

@@ -0,0 +1,211 @@
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
/**
* @brief Component for a generic search page.
*
* This component provides a header with the search field and a ListView to visualise
* search results from the given model.
*/
Kirigami.ScrollablePage {
id: root
/**
* @brief Any additional controls after the search button.
*/
property alias headerTrailing: headerContent.children
/**
* @brief The model that provides the search results.
*
* The model needs to provide the following properties:
* - searchText
* - searching
* Where searchText is the text from the searchField and is used to match results
* and searching is true while the model is finding results.
*
* The model must also provide a search() function to start the search if
* it doesn't do so when the searchText is changed.
*/
property alias model: listView.model
/**
* @brief The number of delegates currently in the view.
*/
property alias count: listView.count
/**
* @brief The delegate to use to visualize the model data.
*/
property alias modelDelegate: listView.delegate
/**
* @brief The delegate to appear as the header of the list.
*/
property alias listHeaderDelegate: listView.header
/**
* @brief The delegate to appear as the footer of the list.
*/
property alias listFooterDelegate: listView.footer
/**
* @brief The placeholder text in the search field.
*/
property alias searchFieldPlaceholder: searchField.placeholderText
/**
* @brief The text to show when no search term has been entered.
*/
property alias noSearchPlaceholderMessage: noSearchMessage.text
/**
* @brief The text to show when no results have been found.
*/
property alias noResultPlaceholderMessage: noResultMessage.text
/**
* @brief The verticalLayoutDirection property of the internal ListView.
*/
property alias listVerticalLayoutDirection: listView.verticalLayoutDirection
/**
* @brief Set the visibility of the search button.
*/
property bool showSearchButton: true
/**
* @brief Message to be shown in a custom placeholder.
* The custom placeholder will be shown if the text is not empty
*/
property alias customPlaceholderText: customPlaceholder.text
/**
* @brief icon for the custom placeholder
*/
property string customPlaceholderIcon: ""
/**
* @brief Force the search field to be focussed.
*/
function focusSearch() {
searchField.forceActiveFocus();
}
/**
* @brief Force the search to be updated if the model has a valid search function.
*/
function updateSearch() {
searchTimer.restart();
}
header: QQC2.Control {
padding: Kirigami.Units.largeSpacing
background: Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.Window
Kirigami.Theme.inherit: false
color: Kirigami.Theme.backgroundColor
Kirigami.Separator {
anchors {
left: parent.left
bottom: parent.bottom
right: parent.right
}
}
}
contentItem: RowLayout {
id: headerContent
spacing: Kirigami.Units.largeSpacing
Kirigami.SearchField {
id: searchField
focus: true
Layout.fillWidth: true
Keys.onEnterPressed: searchButton.clicked()
Keys.onReturnPressed: searchButton.clicked()
onTextChanged: {
searchTimer.restart();
if (model) {
model.searchText = text;
}
}
}
QQC2.Button {
id: searchButton
icon.name: "search"
display: QQC2.Button.IconOnly
visible: root.showSearchButton
text: i18nc("@action:button", "Search")
onClicked: {
if (typeof model.search === 'function') {
model.search();
}
}
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.text: text
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
Timer {
id: searchTimer
interval: 500
running: true
onTriggered: if (typeof model.search === 'function') {
model.search();
}
}
}
}
ListView {
id: listView
Layout.fillWidth: true
Layout.fillHeight: true
spacing: 0
section.property: "section"
Kirigami.PlaceholderMessage {
id: noSearchMessage
anchors.centerIn: parent
visible: searchField.text.length === 0 && listView.count === 0 && customPlaceholder.text.length === 0
}
Kirigami.PlaceholderMessage {
id: noResultMessage
anchors.centerIn: parent
visible: searchField.text.length > 0 && listView.count === 0 && !root.model.searching && customPlaceholder.text.length === 0
}
Kirigami.PlaceholderMessage {
id: customPlaceholder
anchors.centerIn: parent
visible: searchField.text.length > 0 && listView.count === 0 && !root.model.searching && text.length > 0
icon.name: root.customPlaceholderIcon
}
Kirigami.LoadingPlaceholder {
anchors.centerIn: parent
visible: searchField.text.length > 0 && listView.count === 0 && root.model.searching && customPlaceholder.text.length === 0
}
Keys.onUpPressed: {
if (listView.currentIndex > 0) {
listView.decrementCurrentIndex();
} else {
listView.currentIndex = -1; // This is so the list view doesn't appear to have two selected items
listView.headerItem.forceActiveFocus(Qt.TabFocusReason);
}
}
}
}

View File

@@ -0,0 +1,197 @@
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.neochat
QQC2.ComboBox {
id: root
/**
* @brief The connection for the current local user.
*/
required property NeoChatConnection connection
/**
* @brief The server to get the search results from.
*/
property string server
Layout.preferredWidth: Kirigami.Units.gridUnit * 10
Component.onCompleted: currentIndex = 0
textRole: "url"
valueRole: "url"
model: ServerListModel {
id: serverListModel
connection: root.connection
}
delegate: Delegates.RoundedItemDelegate {
id: serverItem
required property int index
required property string url
required property bool isAddServerDelegate
required property bool isHomeServer
required property bool isDeletable
text: isAddServerDelegate ? i18n("Add New Server") : url
highlighted: index === root.highlightedIndex
topInset: index === 0 ? Kirigami.Units.smallSpacing : Math.round(Kirigami.Units.smallSpacing / 2)
bottomInset: index === ListView.view.count - 1 ? Kirigami.Units.smallSpacing : Math.round(Kirigami.Units.smallSpacing / 2)
onClicked: if (isAddServerDelegate) {
addServerSheet.parent = QQC2.Overlay.overlay
addServerSheet.open();
}
contentItem: RowLayout {
spacing: Kirigami.Units.smallSpacing
Delegates.SubtitleContentItem {
itemDelegate: serverItem
subtitle: serverItem.isHomeServer ? i18n("Home Server") : ""
Layout.fillWidth: true
}
QQC2.ToolButton {
visible: serverItem.isAddServerDelegate || serverItem.isDeletable
icon.name: serverItem.isAddServerDelegate ? "list-add" : "dialog-close"
text: i18nc("@action:button", "Add new server")
Accessible.name: text
display: QQC2.AbstractButton.IconOnly
onClicked: {
if (root.currentIndex === serverItem.index && serverItem.isDeletable) {
root.currentIndex = 0;
root.server = root.currentValue;
root.popup.close();
}
if (serverItem.isAddServerDelegate) {
addServerSheet.parent = QQC2.Overlay.overlay
addServerSheet.open();
serverItem.clicked();
} else {
serverListModel.removeServerAtIndex(serverItem.index);
}
}
}
}
}
onActivated: {
if (currentIndex !== count - 1) {
root.server = root.currentValue;
} else {
// Make sure to reset the combobox as it will display nothing if the "Add Server" item was selected.
root.currentIndex = 0;
root.server = root.currentValue;
addServerSheet.parent = QQC2.Overlay.overlay
addServerSheet.open();
}
}
Kirigami.Dialog {
id: addServerSheet
width: Math.min(Kirigami.Units.gridUnit * 15, QQC2.ApplicationWindow.window.width)
title: i18nc("@title:window", "Add server")
horizontalPadding: Kirigami.Units.largeSpacing
onOpened: if (!serverUrlField.isValidServer && !addServerSheet.opened) {
root.currentIndex = 0;
root.server = root.currentValue;
} else if (addServerSheet.opened) {
serverUrlField.forceActiveFocus();
}
onClosed: if (serverUrlField.length <= 0) {
root.currentIndex = root.indexOfValue(root.server);
}
contentItem: ColumnLayout {
spacing: Kirigami.Units.smallSpacing
Kirigami.InlineMessage {
Layout.fillWidth: true
visible: text != ""
text: {
if (serverUrlField.length > 0) {
if (!serverUrlField.acceptableInput) {
return i18n("The entered text is not a valid url");
}
if (!serverUrlField.isValidServer) {
return i18n("This server cannot be resolved or has already been added");
}
}
return "";
}
}
QQC2.Label {
Layout.fillWidth: true
text: i18n("Server URL:")
}
QQC2.TextField {
id: serverUrlField
Layout.fillWidth: true
placeholderText: "kde.org"
property bool isValidServer: false
onTextChanged: {
if (acceptableInput) {
serverListModel.checkServer(text);
}
}
validator: RegularExpressionValidator {
regularExpression: /^([^.]+\.)+[^.]+$/
}
Connections {
target: serverListModel
function onServerCheckComplete(url, valid) {
if (url == serverUrlField.text && valid) {
serverUrlField.isValidServer = true;
}
}
}
}
}
customFooterActions: Kirigami.Action {
text: i18nc("@action:button", "Ok")
enabled: serverUrlField.acceptableInput && serverUrlField.isValidServer
onTriggered: {
serverListModel.addServer(serverUrlField.text);
root.currentIndex = root.indexOfValue(serverUrlField.text);
root.server = root.currentValue;
serverUrlField.text = "";
addServerSheet.close();
}
}
}
}

View File

@@ -0,0 +1,79 @@
// SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
import QtQuick
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.purpose as Purpose
import org.kde.neochat
/**
* Action that allows a user to share data with other apps and services
* installed on their computer. The goal of this high level API is to
* adapt itself for each platform and adopt the native component.
*
* TODO add Android support
*/
Kirigami.Action {
id: root
icon.name: "emblem-shared-symbolic"
text: i18n("Share")
tooltip: i18n("Share the selected media")
visible: false
/**
* This property holds the input data for purpose.
*
* @code{.qml}
* Purpose.ShareAction {
* inputData: {
* 'urls': ['file://home/notroot/Pictures/mypicture.png'],
* 'mimeType': ['image/png']
* }
* }
* @endcode
*/
property var inputData
required property string eventId
required property NeoChatRoom room
property Instantiator _instantiator: Instantiator {
model: Purpose.PurposeAlternativesModel {
pluginType: "Export"
inputData: root.inputData
}
delegate: Kirigami.Action {
property int index
text: model.display
icon.name: model.iconName
onTriggered: {
root.room.download(root.eventId, root.inputData.urls[0]);
root.room.fileTransferCompleted.connect(share);
}
function share(id) {
if (id != root.eventId) {
return;
}
applicationWindow().pageStack.pushDialogLayer(Qt.createComponent("org.kde.neochat", "ShareDialog"), {
title: root.text,
index: index,
model: root._instantiator.model
}, {
title: i18nc("@title", "Share")
});
root.room.fileTransferCompleted.disconnect(share);
}
}
onObjectAdded: (index, object) => {
object.index = index;
root.children.push(object);
}
onObjectRemoved: (index, object) => root.children = Array.from(root.children).filter(obj => obj.pluginId !== object.pluginId)
}
}

View File

@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
import org.kde.kirigami as Kirigami
Kirigami.Action {
property var inputData: ({})
property var room
property string eventId
visible: false
}

View File

@@ -0,0 +1,73 @@
/*
* SPDX-FileCopyrightText: 2017 Atul Sharma <atulsharma406@gmail.com>
* SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls as QQC2
import org.kde.purpose as Purpose
import org.kde.kirigami as Kirigami
import org.kde.notification
import org.kde.neochat
Kirigami.Page {
id: root
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
property alias index: jobView.index
property alias model: jobView.model
QQC2.Action {
shortcut: 'Escape'
onTriggered: root.closeDialog()
}
Notification {
id: sharingFailed
eventId: "Share"
text: i18n("Sharing failed")
urgency: Notification.NormalUrgency
}
Notification {
id: sharingSuccess
eventId: "Share"
flags: Notification.Persistent
}
Component.onCompleted: {
jobView.start();
}
Purpose.JobView {
id: jobView
anchors.fill: parent
onStateChanged: {
if (state === Purpose.PurposeJobController.Finished) {
if (jobView.job?.output?.url?.length > 0) {
sharingSuccess.text = i18n("Shared url for image is <a href='%1'>%1</a>", jobView.job.output.url);
sharingSuccess.sendEvent();
Clipboard.saveText(jobView.job.output.url);
}
root.closeDialog();
} else if (state === Purpose.PurposeJobController.Error) {
// Show failure notification
sharingFailed.sendEvent();
root.closeDialog();
} else if (state === Purpose.PurposeJobController.Cancelled) {
// Do nothing
root.closeDialog();
}
}
}
}

View File

@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2025 Ritchie Frodomar <alkalinethunder@gmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later
pragma Singleton
import QtQuick
import QtTextToSpeech
QtObject {
id: root
readonly property TextToSpeech tts: TextToSpeech {
id: tts
}
function warmUp() {
// TODO: This method is called on startup to avoid a UI freeze the first time you read a message aloud, but there's nothing for it to do.
// This would be a good place to check if TTS can actually be used.
}
function say(text: String) {
tts.say(text)
}
}

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