parent
7644b6e442
commit
f626de0447
@ -306,6 +306,7 @@ set(SRC_FILES
|
|||||||
src/CallDevices.cpp
|
src/CallDevices.cpp
|
||||||
src/CallManager.cpp
|
src/CallManager.cpp
|
||||||
src/ChatPage.cpp
|
src/ChatPage.cpp
|
||||||
|
src/Clipboard.cpp
|
||||||
src/ColorImageProvider.cpp
|
src/ColorImageProvider.cpp
|
||||||
src/CommunitiesList.cpp
|
src/CommunitiesList.cpp
|
||||||
src/CommunitiesListItem.cpp
|
src/CommunitiesListItem.cpp
|
||||||
@ -526,6 +527,7 @@ qt5_wrap_cpp(MOC_HEADERS
|
|||||||
src/CallDevices.h
|
src/CallDevices.h
|
||||||
src/CallManager.h
|
src/CallManager.h
|
||||||
src/ChatPage.h
|
src/ChatPage.h
|
||||||
|
src/Clipboard.h
|
||||||
src/CommunitiesList.h
|
src/CommunitiesList.h
|
||||||
src/CommunitiesListItem.h
|
src/CommunitiesListItem.h
|
||||||
src/CompletionProxyModel.h
|
src/CompletionProxyModel.h
|
||||||
|
@ -177,6 +177,13 @@ Page {
|
|||||||
enabled: visible
|
enabled: visible
|
||||||
text: qsTr("Open in external program")
|
text: qsTr("Open in external program")
|
||||||
onTriggered: TimelineManager.timeline.openMedia(messageContextMenu.eventId)
|
onTriggered: TimelineManager.timeline.openMedia(messageContextMenu.eventId)
|
||||||
|
}
|
||||||
|
|
||||||
|
Platform.MenuItem {
|
||||||
|
visible: messageContextMenu.eventId
|
||||||
|
enabled: visible
|
||||||
|
text: qsTr("Copy link to event")
|
||||||
|
onTriggered: TimelineManager.timeline.copyLinkToEvent(messageContextMenu.eventId)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
23
src/Clipboard.cpp
Normal file
23
src/Clipboard.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "Clipboard.h"
|
||||||
|
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
|
||||||
|
Clipboard::Clipboard(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
connect(
|
||||||
|
QGuiApplication::clipboard(), &QClipboard::dataChanged, this, &Clipboard::textChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Clipboard::setText(QString text)
|
||||||
|
{
|
||||||
|
QGuiApplication::clipboard()->setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
Clipboard::text() const
|
||||||
|
{
|
||||||
|
return QGuiApplication::clipboard()->text();
|
||||||
|
}
|
18
src/Clipboard.h
Normal file
18
src/Clipboard.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class Clipboard : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Clipboard(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QString text() const;
|
||||||
|
void setText(QString text_);
|
||||||
|
signals:
|
||||||
|
void textChanged();
|
||||||
|
};
|
@ -9,13 +9,16 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <QCache>
|
#include <QCache>
|
||||||
|
#include <QClipboard>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QGuiApplication>
|
||||||
#include <QMimeDatabase>
|
#include <QMimeDatabase>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
#include "Cache_p.h"
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "EventAccessors.h"
|
#include "EventAccessors.h"
|
||||||
@ -1336,6 +1339,47 @@ TimelineModel::scrollTimerEvent()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TimelineModel::copyLinkToEvent(QString eventId) const
|
||||||
|
{
|
||||||
|
QStringList vias;
|
||||||
|
|
||||||
|
auto alias = cache::client()->getRoomAliases(room_id_.toStdString());
|
||||||
|
QString room;
|
||||||
|
if (alias) {
|
||||||
|
room = QString::fromStdString(alias->alias);
|
||||||
|
if (room.isEmpty() && !alias->alt_aliases.empty()) {
|
||||||
|
room = QString::fromStdString(alias->alt_aliases.front());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (room.isEmpty())
|
||||||
|
room = room_id_;
|
||||||
|
|
||||||
|
vias.push_back(QString("via=%1").arg(QString(
|
||||||
|
QUrl::toPercentEncoding(QString::fromStdString(http::client()->user_id().hostname())))));
|
||||||
|
auto members = cache::getMembers(room_id_.toStdString(), 0, 100);
|
||||||
|
for (const auto &m : members) {
|
||||||
|
if (vias.size() >= 4)
|
||||||
|
break;
|
||||||
|
|
||||||
|
auto user_id =
|
||||||
|
mtx::identifiers::parse<mtx::identifiers::User>(m.user_id.toStdString());
|
||||||
|
QString server = QString("via=%1").arg(
|
||||||
|
QString(QUrl::toPercentEncoding(QString::fromStdString(user_id.hostname()))));
|
||||||
|
|
||||||
|
if (!vias.contains(server))
|
||||||
|
vias.push_back(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto link = QString("https://matrix.to/#/%1/%2?%3")
|
||||||
|
.arg(QString(QUrl::toPercentEncoding(room)),
|
||||||
|
QString(QUrl::toPercentEncoding(eventId)),
|
||||||
|
vias.join('&'));
|
||||||
|
|
||||||
|
QGuiApplication::clipboard()->setText(link);
|
||||||
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg)
|
TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg)
|
||||||
{
|
{
|
||||||
|
@ -235,6 +235,7 @@ public:
|
|||||||
Q_INVOKABLE void cacheMedia(QString eventId);
|
Q_INVOKABLE void cacheMedia(QString eventId);
|
||||||
Q_INVOKABLE bool saveMedia(QString eventId) const;
|
Q_INVOKABLE bool saveMedia(QString eventId) const;
|
||||||
Q_INVOKABLE void showEvent(QString eventId);
|
Q_INVOKABLE void showEvent(QString eventId);
|
||||||
|
Q_INVOKABLE void copyLinkToEvent(QString eventId) const;
|
||||||
void cacheMedia(QString eventId, std::function<void(const QString filename)> callback);
|
void cacheMedia(QString eventId, std::function<void(const QString filename)> callback);
|
||||||
|
|
||||||
std::vector<::Reaction> reactions(const std::string &event_id)
|
std::vector<::Reaction> reactions(const std::string &event_id)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "BlurhashProvider.h"
|
#include "BlurhashProvider.h"
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
|
#include "Clipboard.h"
|
||||||
#include "ColorImageProvider.h"
|
#include "ColorImageProvider.h"
|
||||||
#include "CompletionProxyModel.h"
|
#include "CompletionProxyModel.h"
|
||||||
#include "DelegateChooser.h"
|
#include "DelegateChooser.h"
|
||||||
@ -214,6 +215,10 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
|
|||||||
QQmlEngine::setObjectOwnership(ptr, QQmlEngine::CppOwnership);
|
QQmlEngine::setObjectOwnership(ptr, QQmlEngine::CppOwnership);
|
||||||
return ptr;
|
return ptr;
|
||||||
});
|
});
|
||||||
|
qmlRegisterSingletonType<Clipboard>(
|
||||||
|
"im.nheko", 1, 0, "Clipboard", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
||||||
|
return new Clipboard();
|
||||||
|
});
|
||||||
|
|
||||||
qRegisterMetaType<mtx::events::collections::TimelineEvents>();
|
qRegisterMetaType<mtx::events::collections::TimelineEvents>();
|
||||||
qRegisterMetaType<std::vector<DeviceInfo>>();
|
qRegisterMetaType<std::vector<DeviceInfo>>();
|
||||||
|
Loading…
Reference in New Issue
Block a user