mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-20 22:41:11 +00:00
Use KUrlMimeData for clipboard xdg-desktop-portal integration
This commit is contained in:
parent
5f53dfda0e
commit
e20840b4d4
@ -85,6 +85,7 @@ PRIVATE
|
||||
desktop-app::external_lz4
|
||||
desktop-app::external_rlottie
|
||||
desktop-app::external_zlib
|
||||
desktop-app::external_kcoreaddons
|
||||
desktop-app::external_qt_static_plugins
|
||||
desktop-app::external_qt
|
||||
desktop-app::external_qr_code_generator
|
||||
|
@ -67,7 +67,7 @@ auto ListFromMimeData(not_null<const QMimeData*> data, bool premium) {
|
||||
auto result = data->hasUrls()
|
||||
? Storage::PrepareMediaList(
|
||||
// When we edit media, we need only 1 file.
|
||||
data->urls().mid(0, 1),
|
||||
base::GetMimeUrls(data).mid(0, 1),
|
||||
st::sendMediaPreviewSize,
|
||||
premium)
|
||||
: Ui::PreparedList(Error::EmptyFile, QString());
|
||||
|
@ -793,13 +793,13 @@ void SendFilesBox::captionResized() {
|
||||
}
|
||||
|
||||
bool SendFilesBox::canAddFiles(not_null<const QMimeData*> data) const {
|
||||
return (data->hasUrls() && CanAddUrls(data->urls())) || data->hasImage();
|
||||
return (data->hasUrls() && CanAddUrls(base::GetMimeUrls(data))) || data->hasImage();
|
||||
}
|
||||
|
||||
bool SendFilesBox::addFiles(not_null<const QMimeData*> data) {
|
||||
const auto premium = _controller->session().premium();
|
||||
auto list = [&] {
|
||||
const auto urls = data->hasUrls() ? data->urls() : QList<QUrl>();
|
||||
const auto urls = data->hasUrls() ? base::GetMimeUrls(data) : QList<QUrl>();
|
||||
auto result = CanAddUrls(urls)
|
||||
? Storage::PrepareMediaList(
|
||||
urls,
|
||||
|
@ -17,10 +17,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include <crl/crl_time.h>
|
||||
#include <QtCore/QReadWriteLock>
|
||||
#include <QtCore/QRegularExpression>
|
||||
#include <QtCore/QMimeData>
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
#include <cmath>
|
||||
#include <set>
|
||||
|
||||
#if __has_include(<KUrlMimeData>)
|
||||
#include <KUrlMimeData>
|
||||
#endif
|
||||
|
||||
#define qsl(s) QStringLiteral(s)
|
||||
|
||||
namespace base {
|
||||
@ -30,6 +35,16 @@ inline bool in_range(Value &&value, From &&from, Till &&till) {
|
||||
return (value >= from) && (value < till);
|
||||
}
|
||||
|
||||
inline auto GetMimeUrls(const QMimeData *data) {
|
||||
#if __has_include(<KUrlMimeData>)
|
||||
return KUrlMimeData::urlsFromMimeData(
|
||||
data,
|
||||
KUrlMimeData::PreferLocalUrls);
|
||||
#else
|
||||
return data->urls();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
|
||||
static const int32 ScrollMax = INT_MAX;
|
||||
|
@ -206,7 +206,7 @@ void Paint::handleMimeData(const QMimeData *data) {
|
||||
const auto premium = false; // Don't support > 2GB files here.
|
||||
auto result = data->hasUrls()
|
||||
? Storage::PrepareMediaList(
|
||||
data->urls().mid(0, 1),
|
||||
base::GetMimeUrls(data).mid(0, 1),
|
||||
_imageSize.width() / 2,
|
||||
premium)
|
||||
: Ui::PreparedList(Error::EmptyFile, QString());
|
||||
|
@ -5113,7 +5113,7 @@ bool HistoryWidget::canSendFiles(not_null<const QMimeData*> data) const {
|
||||
return false;
|
||||
} else if (data->hasImage()) {
|
||||
return true;
|
||||
} else if (const auto urls = data->urls(); !urls.empty()) {
|
||||
} else if (const auto urls = base::GetMimeUrls(data); !urls.empty()) {
|
||||
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
|
||||
return true;
|
||||
}
|
||||
@ -5132,7 +5132,7 @@ bool HistoryWidget::confirmSendingFiles(
|
||||
const auto hasImage = data->hasImage();
|
||||
const auto premium = controller()->session().user()->isPremium();
|
||||
|
||||
if (const auto urls = data->urls(); !urls.empty()) {
|
||||
if (const auto urls = base::GetMimeUrls(data); !urls.empty()) {
|
||||
auto list = Storage::PrepareMediaList(
|
||||
urls,
|
||||
st::sendMediaPreviewSize,
|
||||
|
@ -81,7 +81,7 @@ constexpr auto kRefreshSlowmodeLabelTimeout = crl::time(200);
|
||||
bool CanSendFiles(not_null<const QMimeData*> data) {
|
||||
if (data->hasImage()) {
|
||||
return true;
|
||||
} else if (const auto urls = data->urls(); !urls.empty()) {
|
||||
} else if (const auto urls = base::GetMimeUrls(data); !urls.empty()) {
|
||||
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
|
||||
return true;
|
||||
}
|
||||
@ -707,7 +707,7 @@ bool RepliesWidget::confirmSendingFiles(
|
||||
const auto hasImage = data->hasImage();
|
||||
const auto premium = controller()->session().user()->isPremium();
|
||||
|
||||
if (const auto urls = data->urls(); !urls.empty()) {
|
||||
if (const auto urls = base::GetMimeUrls(data); !urls.empty()) {
|
||||
auto list = Storage::PrepareMediaList(
|
||||
urls,
|
||||
st::sendMediaPreviewSize,
|
||||
|
@ -70,7 +70,7 @@ namespace {
|
||||
bool CanSendFiles(not_null<const QMimeData*> data) {
|
||||
if (data->hasImage()) {
|
||||
return true;
|
||||
} else if (const auto urls = data->urls(); !urls.empty()) {
|
||||
} else if (const auto urls = base::GetMimeUrls(data); !urls.empty()) {
|
||||
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
|
||||
return true;
|
||||
}
|
||||
@ -363,7 +363,7 @@ bool ScheduledWidget::confirmSendingFiles(
|
||||
const auto hasImage = data->hasImage();
|
||||
const auto premium = controller()->session().user()->isPremium();
|
||||
|
||||
if (const auto urls = data->urls(); !urls.empty()) {
|
||||
if (const auto urls = base::GetMimeUrls(data); !urls.empty()) {
|
||||
auto list = Storage::PrepareMediaList(
|
||||
urls,
|
||||
st::sendMediaPreviewSize,
|
||||
|
@ -88,14 +88,14 @@ void PrepareDetailsInParallel(PreparedList &result, int previewWidth) {
|
||||
} // namespace
|
||||
|
||||
bool ValidatePhotoEditorMediaDragData(not_null<const QMimeData*> data) {
|
||||
if (data->urls().size() > 1) {
|
||||
if (base::GetMimeUrls(data).size() > 1) {
|
||||
return false;
|
||||
} else if (data->hasImage()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (data->hasUrls()) {
|
||||
const auto url = data->urls().front();
|
||||
const auto url = base::GetMimeUrls(data).front();
|
||||
if (url.isLocalFile()) {
|
||||
using namespace Core;
|
||||
const auto info = QFileInfo(Platform::File::UrlToLocal(url));
|
||||
@ -111,14 +111,14 @@ bool ValidatePhotoEditorMediaDragData(not_null<const QMimeData*> data) {
|
||||
bool ValidateEditMediaDragData(
|
||||
not_null<const QMimeData*> data,
|
||||
Ui::AlbumType albumType) {
|
||||
if (data->urls().size() > 1) {
|
||||
if (base::GetMimeUrls(data).size() > 1) {
|
||||
return false;
|
||||
} else if (data->hasImage()) {
|
||||
return (albumType != Ui::AlbumType::Music);
|
||||
}
|
||||
|
||||
if (albumType == Ui::AlbumType::PhotoVideo && data->hasUrls()) {
|
||||
const auto url = data->urls().front();
|
||||
const auto url = base::GetMimeUrls(data).front();
|
||||
if (url.isLocalFile()) {
|
||||
using namespace Core;
|
||||
const auto info = QFileInfo(Platform::File::UrlToLocal(url));
|
||||
@ -143,7 +143,7 @@ MimeDataState ComputeMimeDataState(const QMimeData *data) {
|
||||
return MimeDataState::None;
|
||||
}
|
||||
|
||||
const auto &urls = data->urls();
|
||||
const auto &urls = base::GetMimeUrls(data);
|
||||
if (urls.isEmpty()) {
|
||||
return MimeDataState::None;
|
||||
}
|
||||
|
@ -1000,6 +1000,7 @@ void MainWindow::launchDrag(
|
||||
// Qt destroys this QDrag automatically after the drag is finished
|
||||
// We must not delete this at the end of this function, as this breaks DnD on Linux
|
||||
auto drag = new QDrag(this);
|
||||
KUrlMimeData::exportUrlsToPortal(data.get());
|
||||
drag->setMimeData(data.release());
|
||||
drag->exec(Qt::CopyAction);
|
||||
|
||||
|
@ -48,6 +48,15 @@ RUN git clone {{ GIT }}/desktop-app/patches.git \
|
||||
&& git checkout 4a5c759f8f \
|
||||
&& rm -rf .git
|
||||
|
||||
FROM builder AS extra-cmake-modules
|
||||
RUN git clone -b v5.97.0 --depth=1 {{ GIT }}/KDE/extra-cmake-modules.git \
|
||||
&& cd extra-cmake-modules \
|
||||
&& cmake -GNinja -B build . -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF \
|
||||
&& cmake --build build --parallel \
|
||||
&& DESTDIR="{{ LibrariesPath }}/extra-cmake-modules-cache" cmake --install build \
|
||||
&& cd .. \
|
||||
&& rm -rf extra-cmake-modules
|
||||
|
||||
FROM builder AS libffi
|
||||
RUN git clone -b v3.4.2 --depth=1 {{ GIT }}/libffi/libffi.git \
|
||||
&& cd libffi \
|
||||
@ -546,6 +555,7 @@ ENV OPENSSL_ROOT_DIR {{ OPENSSL_PREFIX }}
|
||||
RUN git clone -b {{ QT_TAG }} --depth=1 git://code.qt.io/qt/qt5.git qt_{{ QT }} \
|
||||
&& cd qt_{{ QT }} \
|
||||
&& git submodule update --init --recursive --depth=1 qtbase qtwayland qtimageformats qtsvg qt5compat \
|
||||
&& git submodule update --init --recursive qttools \
|
||||
&& cd qtbase \
|
||||
&& find ../../patches/qtbase_{{ QT }} -type f -print0 | sort -z | xargs -r0 git apply \
|
||||
&& cd .. \
|
||||
@ -575,6 +585,37 @@ RUN git clone -b {{ QT_TAG }} --depth=1 git://code.qt.io/qt/qt5.git qt_{{ QT }}
|
||||
&& cd .. \
|
||||
&& rm -rf qt_{{ QT }}
|
||||
|
||||
FROM patches AS kcoreaddons
|
||||
COPY --link --from=extra-cmake-modules {{ LibrariesPath }}/extra-cmake-modules-cache /
|
||||
COPY --link --from=libffi {{ LibrariesPath }}/libffi-cache /
|
||||
COPY --link --from=zlib {{ LibrariesPath }}/zlib-cache /
|
||||
COPY --link --from=libproxy {{ LibrariesPath }}/libproxy-cache /
|
||||
COPY --link --from=mozjpeg {{ LibrariesPath }}/mozjpeg-cache /
|
||||
COPY --link --from=xcb {{ LibrariesPath }}/xcb-cache /
|
||||
COPY --link --from=xcb-wm {{ LibrariesPath }}/xcb-wm-cache /
|
||||
COPY --link --from=xcb-util {{ LibrariesPath }}/xcb-util-cache /
|
||||
COPY --link --from=xcb-image {{ LibrariesPath }}/xcb-image-cache /
|
||||
COPY --link --from=xcb-keysyms {{ LibrariesPath }}/xcb-keysyms-cache /
|
||||
COPY --link --from=xcb-render-util {{ LibrariesPath }}/xcb-render-util-cache /
|
||||
COPY --link --from=wayland {{ LibrariesPath }}/wayland-cache /
|
||||
COPY --link --from=openssl {{ LibrariesPath }}/openssl-cache /
|
||||
COPY --link --from=xkbcommon {{ LibrariesPath }}/xkbcommon-cache /
|
||||
COPY --link --from=qt {{ LibrariesPath }}/qt-cache /
|
||||
|
||||
RUN git clone -b v5.97.0 --depth=1 {{ GIT }}/KDE/kcoreaddons.git \
|
||||
&& cd kcoreaddons \
|
||||
&& cmake -GNinja -B build . \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH={{ QT_PREFIX }} \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DBUILD_TESTING=OFF \
|
||||
-DBUILD_WITH_QT6=ON \
|
||||
-DEXCLUDE_DEPRECATED_BEFORE_AND_AT=5.78.0 \
|
||||
&& cmake --build build --parallel \
|
||||
&& DESTDIR="{{ LibrariesPath }}/kcoreaddons-cache" cmake --install build \
|
||||
&& cd .. \
|
||||
&& rm -rf kcoreaddons
|
||||
|
||||
FROM patches AS breakpad
|
||||
RUN git clone https://chromium.googlesource.com/breakpad/breakpad.git \
|
||||
&& cd breakpad \
|
||||
@ -662,6 +703,7 @@ COPY --link --from=xkbcommon {{ LibrariesPath }}/xkbcommon-cache /
|
||||
COPY --link --from=libsigcplusplus {{ LibrariesPath }}/libsigcplusplus-cache /
|
||||
COPY --link --from=glibmm {{ LibrariesPath }}/glibmm-cache /
|
||||
COPY --link --from=qt {{ LibrariesPath }}/qt-cache /
|
||||
COPY --link --from=kcoreaddons {{ LibrariesPath }}/kcoreaddons-cache /
|
||||
COPY --link --from=breakpad {{ LibrariesPath }}/breakpad-cache /
|
||||
COPY --link --from=webrtc {{ LibrariesPath }}/tg_owt tg_owt
|
||||
COPY --link --from=webrtc_release {{ LibrariesPath }}/tg_owt/out/Release tg_owt/out/Release
|
||||
|
2
cmake
2
cmake
@ -1 +1 @@
|
||||
Subproject commit d5190185f74d8f76e610caeb6e45642fca2c177f
|
||||
Subproject commit 7b43684a1caab158ef0b8884c20fe9d1436872ab
|
@ -154,6 +154,7 @@ parts:
|
||||
after:
|
||||
- desktop-qt
|
||||
- ffmpeg
|
||||
- kcoreaddons
|
||||
- mozjpeg
|
||||
- openal
|
||||
- openssl
|
||||
@ -196,6 +197,17 @@ parts:
|
||||
- mozjpeg
|
||||
- qt
|
||||
|
||||
extra-cmake-modules:
|
||||
source: https://github.com/KDE/extra-cmake-modules.git
|
||||
source-depth: 1
|
||||
source-tag: v5.97.0
|
||||
plugin: cmake
|
||||
cmake-parameters:
|
||||
- -DCMAKE_BUILD_TYPE=Release
|
||||
- -DCMAKE_INSTALL_PREFIX=/usr
|
||||
- -DBUILD_TESTING=OFF
|
||||
prime: [-./*]
|
||||
|
||||
ffmpeg:
|
||||
plugin: nil
|
||||
build-packages:
|
||||
@ -215,6 +227,28 @@ parts:
|
||||
after:
|
||||
- mozjpeg
|
||||
|
||||
kcoreaddons:
|
||||
source: https://github.com/KDE/kcoreaddons.git
|
||||
source-depth: 1
|
||||
source-tag: v5.97.0
|
||||
plugin: cmake
|
||||
cmake-parameters:
|
||||
- -DCMAKE_BUILD_TYPE=Release
|
||||
- -DCMAKE_INSTALL_PREFIX=/usr
|
||||
- -DBUILD_TESTING=OFF
|
||||
- -DBUILD_WITH_QT6=ON
|
||||
- -DEXCLUDE_DEPRECATED_BEFORE_AND_AT=5.78.0
|
||||
prime:
|
||||
- -./usr/bin
|
||||
- -./usr/include
|
||||
- -./usr/lib/$SNAPCRAFT_ARCH_TRIPLET/cmake
|
||||
- -./usr/lib/$SNAPCRAFT_ARCH_TRIPLET/*.so
|
||||
- -./usr/mkspecs
|
||||
after:
|
||||
- extra-cmake-modules
|
||||
- desktop-qt
|
||||
- qttools
|
||||
|
||||
mozjpeg:
|
||||
source: https://github.com/mozilla/mozjpeg.git
|
||||
source-depth: 1
|
||||
@ -407,6 +441,22 @@ parts:
|
||||
- openssl
|
||||
- patches
|
||||
|
||||
qttools:
|
||||
source: git://code.qt.io/qt/qttools.git
|
||||
source-depth: 1
|
||||
source-tag: v6.3.1
|
||||
plugin: cmake
|
||||
build-packages:
|
||||
- clang
|
||||
- libclang-dev
|
||||
- llvm-dev
|
||||
cmake-parameters:
|
||||
- -DCMAKE_BUILD_TYPE=Release
|
||||
- -DCMAKE_INSTALL_PREFIX=/usr
|
||||
prime: [-./*]
|
||||
after:
|
||||
- qt
|
||||
|
||||
rnnoise:
|
||||
source: https://gitlab.xiph.org/xiph/rnnoise.git
|
||||
source-depth: 1
|
||||
|
Loading…
Reference in New Issue
Block a user