From e20840b4d4c828d930b55a93995ded9eb2784c2d Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 27 Aug 2022 01:45:38 +0400 Subject: [PATCH] Use KUrlMimeData for clipboard xdg-desktop-portal integration --- Telegram/CMakeLists.txt | 1 + .../SourceFiles/boxes/edit_caption_box.cpp | 2 +- Telegram/SourceFiles/boxes/send_files_box.cpp | 4 +- Telegram/SourceFiles/core/utils.h | 15 ++++++ Telegram/SourceFiles/editor/editor_paint.cpp | 2 +- .../SourceFiles/history/history_widget.cpp | 4 +- .../view/history_view_replies_section.cpp | 4 +- .../view/history_view_scheduled_section.cpp | 4 +- .../storage/storage_media_prepare.cpp | 10 ++-- Telegram/SourceFiles/window/main_window.cpp | 1 + Telegram/build/docker/centos_env/Dockerfile | 42 ++++++++++++++++ cmake | 2 +- snap/snapcraft.yaml | 50 +++++++++++++++++++ 13 files changed, 125 insertions(+), 16 deletions(-) diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 153e9d4c9..0e151a5c9 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -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 diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 56ce394b5..46d3e8541 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -67,7 +67,7 @@ auto ListFromMimeData(not_null 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()); diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index c9c4b25b0..1ad674737 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -793,13 +793,13 @@ void SendFilesBox::captionResized() { } bool SendFilesBox::canAddFiles(not_null data) const { - return (data->hasUrls() && CanAddUrls(data->urls())) || data->hasImage(); + return (data->hasUrls() && CanAddUrls(base::GetMimeUrls(data))) || data->hasImage(); } bool SendFilesBox::addFiles(not_null data) { const auto premium = _controller->session().premium(); auto list = [&] { - const auto urls = data->hasUrls() ? data->urls() : QList(); + const auto urls = data->hasUrls() ? base::GetMimeUrls(data) : QList(); auto result = CanAddUrls(urls) ? Storage::PrepareMediaList( urls, diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index c3794e9cb..39a813b68 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -17,10 +17,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include +#include #include #include #include +#if __has_include() +#include +#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() + return KUrlMimeData::urlsFromMimeData( + data, + KUrlMimeData::PreferLocalUrls); +#else + return data->urls(); +#endif +} + } // namespace base static const int32 ScrollMax = INT_MAX; diff --git a/Telegram/SourceFiles/editor/editor_paint.cpp b/Telegram/SourceFiles/editor/editor_paint.cpp index 6be33133c..08125a5b0 100644 --- a/Telegram/SourceFiles/editor/editor_paint.cpp +++ b/Telegram/SourceFiles/editor/editor_paint.cpp @@ -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()); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index dd0ed303e..60ff6fa59 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -5113,7 +5113,7 @@ bool HistoryWidget::canSendFiles(not_null 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, diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 4f9d75c88..3fac97fef 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -81,7 +81,7 @@ constexpr auto kRefreshSlowmodeLabelTimeout = crl::time(200); bool CanSendFiles(not_null 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, diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 5370172db..9423a53ad 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -70,7 +70,7 @@ namespace { bool CanSendFiles(not_null 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, diff --git a/Telegram/SourceFiles/storage/storage_media_prepare.cpp b/Telegram/SourceFiles/storage/storage_media_prepare.cpp index 03cf870fb..76e6c608e 100644 --- a/Telegram/SourceFiles/storage/storage_media_prepare.cpp +++ b/Telegram/SourceFiles/storage/storage_media_prepare.cpp @@ -88,14 +88,14 @@ void PrepareDetailsInParallel(PreparedList &result, int previewWidth) { } // namespace bool ValidatePhotoEditorMediaDragData(not_null 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 data) { bool ValidateEditMediaDragData( not_null 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; } diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 0940c72ec..22ed0ce8d 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -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); diff --git a/Telegram/build/docker/centos_env/Dockerfile b/Telegram/build/docker/centos_env/Dockerfile index c98d68198..febe3a207 100644 --- a/Telegram/build/docker/centos_env/Dockerfile +++ b/Telegram/build/docker/centos_env/Dockerfile @@ -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 diff --git a/cmake b/cmake index d5190185f..7b43684a1 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit d5190185f74d8f76e610caeb6e45642fca2c177f +Subproject commit 7b43684a1caab158ef0b8884c20fe9d1436872ab diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index f9bc7b219..3a3a25fad 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -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