[vlc-commits] [Git][videolan/vlc][master] 3 commits: qml: use StandardKey.Paste instead of "Ctrl+V" in GlobalShortcuts

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Mon Dec 9 05:57:44 UTC 2024



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
a1ac2b55 by Fatih Uzunoglu at 2024-12-09T05:42:58+00:00
qml: use StandardKey.Paste instead of "Ctrl+V" in GlobalShortcuts

- - - - -
35c7b37d by Fatih Uzunoglu at 2024-12-09T05:42:58+00:00
qt: introduce `MainCtx::pasteFromClipboard()`

- - - - -
fa60a909 by Fatih Uzunoglu at 2024-12-09T05:42:58+00:00
qml: use `MainCtx::pasteFromClipboard()` in GlobalShortcuts

- - - - -


3 changed files:

- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/maininterface/mainctx.hpp
- modules/gui/qt/menus/qml/GlobalShortcuts.qml


Changes:

=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -61,6 +61,8 @@
 #include <QUrl>
 #include <QDate>
 #include <QMimeData>
+#include <QClipboard>
+#include <QInputDialog>
 
 #include <QQmlProperty>
 #include <QQmlContext>
@@ -829,6 +831,66 @@ VLCVarChoiceModel* MainCtx::getExtraInterfaces()
     return m_extraInterfaces;
 }
 
+bool MainCtx::pasteFromClipboard()
+{
+    assert(qApp);
+    const QClipboard *const clipboard = qApp->clipboard();
+    if (Q_UNLIKELY(!clipboard))
+        return false;
+    const QMimeData *mimeData = clipboard->mimeData(QClipboard::Selection);
+    if (!mimeData || !mimeData->hasUrls())
+        mimeData = clipboard->mimeData(QClipboard::Clipboard);
+
+    if (Q_UNLIKELY(!mimeData))
+        return false;
+
+    QList<QUrl> urlList = mimeData->urls();
+    QString text = mimeData->text();
+
+    if (urlList.count() > 1 || text.contains('\n'))
+    {
+        // NOTE: The reason that mime data for `text/uri-list` is not used
+        //       directly as the placeholder of the input dialog instead of
+        //       re-constructing is to decode the urls in the list.
+        QString placeholder;
+
+        if (urlList.isEmpty())
+        {
+            placeholder = std::move(text);
+        }
+        else
+        {
+            for (const auto& i : urlList)
+                placeholder += i.toString(QUrl::PrettyDecoded) + '\n';
+            placeholder.chop(1);
+        }
+
+        bool ok = false;
+        const QString ret = QInputDialog::getMultiLineText(nullptr,
+                                                           qtr("Paste from clipboard"),
+                                                           qtr("Do you want to enqueue the following URLs into the playlist?"),
+                                                           placeholder,
+                                                           &ok);
+        if (!ok)
+            return false;
+
+        for (const auto& i : QStringView(ret).split('\n'))
+        {
+            if (i.length() > 0)
+                THEMPL->append(i.trimmed().toString(), false);
+        }
+
+        return true;
+    }
+    else if ((urlList.count() == 1) || mimeData->hasText())
+    {
+        THEDP->openUrlDialog();
+        return true;
+    }
+
+    return false;
+}
+
 /*****************************************************************************
  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
  *  We don't show the menu directly here because we don't want the


=====================================
modules/gui/qt/maininterface/mainctx.hpp
=====================================
@@ -439,6 +439,8 @@ public slots:
     virtual void reloadPrefs();
     VLCVarChoiceModel* getExtraInterfaces();
 
+    bool pasteFromClipboard();
+
 protected slots:
     void onInputChanged( bool );
 


=====================================
modules/gui/qt/menus/qml/GlobalShortcuts.qml
=====================================
@@ -28,7 +28,7 @@ Item {
     ShortcutExt{ sequence:"Ctrl+D"; onActivated: DialogsProvider.openDiscDialog(); }
     ShortcutExt{ sequence:"Ctrl+N"; onActivated: DialogsProvider.openNetDialog(); }
     ShortcutExt{ sequence:"Ctrl+C"; onActivated: DialogsProvider.openCaptureDialog(); }
-    ShortcutExt{ sequence:"Ctrl+V"; onActivated: DialogsProvider.openUrlDialog(); }
+    ShortcutExt{ sequence: StandardKey.Paste; onActivated: MainCtx.pasteFromClipboard(); }
     ShortcutExt{ context: Qt.WindowShortcut; sequence:"Ctrl+Y"; onActivated: DialogsProvider.savePlayingToPlaylist(); }
     ShortcutExt{ sequence:"Ctrl+R"; onActivated: DialogsProvider.openAndTranscodingDialogs(); }
     ShortcutExt{ sequence:"Ctrl+S"; onActivated: DialogsProvider.openAndStreamingDialogs(); }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7172b84dd5a07dd19144abac14bda71ce9db87ad...fa60a909932d5b9ff654233b0632737479fa94fe

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7172b84dd5a07dd19144abac14bda71ce9db87ad...fa60a909932d5b9ff654233b0632737479fa94fe
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list