mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-19 10:16:34 +01:00
Add selection dialog for media capture request
Available from Qt 6.7 onwards. Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
32e2f2962e
commit
2dcb1748da
@ -145,6 +145,7 @@ set(SRCS ${SRCS}
|
||||
other/browsinglibrary.cpp
|
||||
other/clearprivatedata.cpp
|
||||
other/checkboxdialog.cpp
|
||||
other/comboboxdialog.cpp
|
||||
other/iconchooser.cpp
|
||||
other/licenseviewer.cpp
|
||||
other/qzsettings.cpp
|
||||
@ -379,6 +380,7 @@ set(SRCS ${SRCS}
|
||||
other/browsinglibrary.h
|
||||
other/clearprivatedata.h
|
||||
other/checkboxdialog.h
|
||||
other/comboboxdialog.h
|
||||
other/iconchooser.h
|
||||
other/licenseviewer.h
|
||||
other/qzsettings.h
|
||||
|
61
src/lib/other/comboboxdialog.cpp
Normal file
61
src/lib/other/comboboxdialog.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* SPDX-FileCopyrightText: 2024 Juraj Oravec <jurajoravec@mailo.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* ============================================================ */
|
||||
|
||||
#include "comboboxdialog.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QSpacerItem>
|
||||
|
||||
ComboBoxDialog::ComboBoxDialog(const QDialogButtonBox::StandardButtons buttons, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
m_gridLayout = new QGridLayout();
|
||||
m_label = new QLabel();
|
||||
m_description = new QLabel();
|
||||
m_comboBox = new QComboBox();
|
||||
|
||||
m_hLayout = new QHBoxLayout();
|
||||
m_buttonBox = new QDialogButtonBox(buttons);
|
||||
m_hSpacerLeft = new QSpacerItem(40, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);
|
||||
m_hSpacerRight = new QSpacerItem(40, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);
|
||||
|
||||
m_hLayout->addItem(m_hSpacerLeft);
|
||||
m_hLayout->addWidget(m_buttonBox);
|
||||
m_hLayout->addItem(m_hSpacerRight);
|
||||
|
||||
m_gridLayout->addWidget(m_description, 0, 0, 1, 2);
|
||||
m_gridLayout->addWidget(m_label, 1, 0);
|
||||
m_gridLayout->addWidget(m_comboBox, 1, 1);
|
||||
m_gridLayout->addLayout(m_hLayout, 2, 0, 1, 2);
|
||||
|
||||
setLayout(m_gridLayout);
|
||||
|
||||
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
}
|
||||
|
||||
void ComboBoxDialog::setLabel(const QString& label)
|
||||
{
|
||||
m_label->setText(label);
|
||||
}
|
||||
|
||||
void ComboBoxDialog::setModel(QAbstractItemModel* model)
|
||||
{
|
||||
m_comboBox->setModel(model);
|
||||
}
|
||||
|
||||
int ComboBoxDialog::currentIndex()
|
||||
{
|
||||
return m_comboBox->currentIndex();
|
||||
}
|
||||
|
||||
void ComboBoxDialog::setDescription(const QString& description)
|
||||
{
|
||||
m_description->setText(description);
|
||||
}
|
47
src/lib/other/comboboxdialog.h
Normal file
47
src/lib/other/comboboxdialog.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* SPDX-FileCopyrightText: 2024 Juraj Oravec <jurajoravec@mailo.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* ============================================================ */
|
||||
|
||||
#ifndef COMBOBOXDIALOG_H
|
||||
#define COMBOBOXDIALOG_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class QComboBox;
|
||||
class QGridLayout;
|
||||
class QHBoxLayout;
|
||||
class QLabel;
|
||||
class QSpacerItem;
|
||||
|
||||
class FALKON_EXPORT ComboBoxDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ComboBoxDialog(const QDialogButtonBox::StandardButtons buttons, QWidget* parent = nullptr);
|
||||
|
||||
void setModel(QAbstractItemModel *model);
|
||||
void setLabel(const QString &label);
|
||||
void setDescription(const QString &description);
|
||||
|
||||
int currentIndex();
|
||||
|
||||
private:
|
||||
QComboBox *m_comboBox;
|
||||
QLabel *m_label;
|
||||
QLabel *m_description;
|
||||
|
||||
QGridLayout *m_gridLayout;
|
||||
QHBoxLayout *m_hLayout;
|
||||
QDialogButtonBox *m_buttonBox;
|
||||
QSpacerItem *m_hSpacerLeft;
|
||||
QSpacerItem *m_hSpacerRight;
|
||||
};
|
||||
|
||||
#endif // COMBOBOXDIALOG_H
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "passwordmanager.h"
|
||||
#include "scripts.h"
|
||||
#include "ocssupport.h"
|
||||
#include "comboboxdialog.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -60,9 +61,15 @@
|
||||
#include <QPushButton>
|
||||
#include <QUrlQuery>
|
||||
#include <QtWebEngineWidgetsVersion>
|
||||
#include <QtWebEngineCoreVersion>
|
||||
|
||||
#include <QWebEngineRegisterProtocolHandlerRequest>
|
||||
|
||||
#if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(6, 7, 0)
|
||||
#include <QConcatenateTablesProxyModel>
|
||||
#include <QWebEngineDesktopMediaRequest>
|
||||
#endif
|
||||
|
||||
QString WebPage::s_lastUploadLocation = QDir::homePath();
|
||||
QUrl WebPage::s_lastUnsupportedUrl;
|
||||
QElapsedTimer WebPage::s_lastUnsupportedUrlTime;
|
||||
@ -118,6 +125,9 @@ WebPage::WebPage(QObject* parent)
|
||||
// TODO: It should prompt user
|
||||
selection.select(selection.certificates().at(0));
|
||||
});
|
||||
#if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(6, 7, 0)
|
||||
connect(this, &QWebEnginePage::desktopMediaRequested, this, &WebPage::handleDesktopMediaRequested);
|
||||
#endif
|
||||
}
|
||||
|
||||
WebPage::~WebPage()
|
||||
@ -765,3 +775,41 @@ QWebEnginePage* WebPage::createWindow(QWebEnginePage::WebWindowType type)
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(6, 7, 0)
|
||||
void WebPage::handleDesktopMediaRequested(const QWebEngineDesktopMediaRequest& request)
|
||||
{
|
||||
if (!mApp->webSettings()->testAttribute(QWebEngineSettings::ScreenCaptureEnabled)) {
|
||||
request.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
QConcatenateTablesProxyModel proxyModel;
|
||||
proxyModel.addSourceModel(request.screensModel());
|
||||
proxyModel.addSourceModel(request.windowsModel());
|
||||
|
||||
ComboBoxDialog dialog(QDialogButtonBox::StandardButton::Ok | QDialogButtonBox::StandardButton::Cancel);
|
||||
dialog.setLabel(tr("Source:"));
|
||||
dialog.setDescription(tr("Select cource for <b>%1</b> to capture.").arg(url().host()));
|
||||
dialog.setModel(&proxyModel);
|
||||
|
||||
dialog.exec();
|
||||
|
||||
if (dialog.result() != QDialog::Rejected) {
|
||||
auto index = proxyModel.mapToSource(proxyModel.index(dialog.currentIndex(), 0));
|
||||
|
||||
if (index.model() == request.screensModel()) {
|
||||
request.selectScreen(index);
|
||||
}
|
||||
else if (index.model() == request.windowsModel()) {
|
||||
request.selectWindow(index);
|
||||
}
|
||||
else {
|
||||
request.cancel();
|
||||
}
|
||||
}
|
||||
else {
|
||||
request.cancel();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -35,6 +35,10 @@ class WebView;
|
||||
class WebHitTestResult;
|
||||
class DelayedFileWatcher;
|
||||
|
||||
#if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(6, 7, 0)
|
||||
class QWebEngineDesktopMediaRequest;
|
||||
#endif
|
||||
|
||||
class FALKON_EXPORT WebPage : public QWebEnginePage
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -96,6 +100,10 @@ private Q_SLOTS:
|
||||
void renderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode);
|
||||
void onCertificateError(QWebEngineCertificateError error);
|
||||
|
||||
#if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(6, 7, 0)
|
||||
void handleDesktopMediaRequested(const QWebEngineDesktopMediaRequest &request);
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user