Changeset View
Changeset View
Standalone View
Standalone View
src/screenchooserdialog.cpp
Show All 14 Lines | |||||
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
16 | * | 16 | * | ||
17 | * Authors: | 17 | * Authors: | ||
18 | * Jan Grulich <jgrulich@redhat.com> | 18 | * Jan Grulich <jgrulich@redhat.com> | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "screenchooserdialog.h" | 21 | #include "screenchooserdialog.h" | ||
22 | #include "ui_screenchooserdialog.h" | 22 | #include "ui_screenchooserdialog.h" | ||
23 | #include "waylandintegration.h" | ||||
23 | 24 | | |||
24 | #include <KLocalizedString> | 25 | #include <KLocalizedString> | ||
25 | #include <QPushButton> | 26 | #include <QPushButton> | ||
26 | #include <QStandardPaths> | 27 | #include <QStandardPaths> | ||
27 | #include <QSettings> | 28 | #include <QSettings> | ||
29 | #include <KWayland/Client/plasmawindowmodel.h> | ||||
30 | #include <KWayland/Client/plasmawindowmanagement.h> | ||||
28 | 31 | | |||
29 | ScreenChooserDialog::ScreenChooserDialog(const QString &appName, bool multiple, QDialog *parent, Qt::WindowFlags flags) | 32 | ScreenChooserDialog::ScreenChooserDialog(const QString &appName, bool multiple, QDialog *parent, Qt::WindowFlags flags) | ||
30 | : QDialog(parent, flags) | 33 | : QDialog(parent, flags) | ||
31 | , m_dialog(new Ui::ScreenChooserDialog) | 34 | , m_dialog(new Ui::ScreenChooserDialog) | ||
32 | { | 35 | { | ||
33 | m_dialog->setupUi(this); | 36 | m_dialog->setupUi(this); | ||
34 | 37 | | |||
35 | if (multiple) { | 38 | if (multiple) { | ||
36 | m_dialog->screenView->setSelectionMode(QAbstractItemView::ExtendedSelection); | 39 | m_dialog->screenView->setSelectionMode(QAbstractItemView::ExtendedSelection); | ||
37 | } | 40 | } | ||
38 | 41 | | |||
39 | connect(m_dialog->buttonBox, &QDialogButtonBox::accepted, this, &ScreenChooserDialog::accept); | 42 | connect(m_dialog->buttonBox, &QDialogButtonBox::accepted, this, &ScreenChooserDialog::accept); | ||
40 | connect(m_dialog->buttonBox, &QDialogButtonBox::rejected, this, &ScreenChooserDialog::reject); | 43 | connect(m_dialog->buttonBox, &QDialogButtonBox::rejected, this, &ScreenChooserDialog::reject); | ||
41 | connect(m_dialog->screenView, &QListWidget::itemDoubleClicked, this, &ScreenChooserDialog::accept); | 44 | connect(m_dialog->screenView, &QListWidget::itemDoubleClicked, this, &ScreenChooserDialog::accept); | ||
42 | 45 | | |||
46 | auto model = new KWayland::Client::PlasmaWindowModel(WaylandIntegration::plasmaWindowManagement()); | ||||
47 | m_dialog->windowsView->setModel(model); | ||||
48 | | ||||
43 | m_dialog->buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("Share")); | 49 | m_dialog->buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("Share")); | ||
44 | 50 | | |||
45 | QString applicationName; | 51 | QString applicationName; | ||
46 | const QString desktopFile = appName + QLatin1String(".desktop"); | 52 | const QString desktopFile = appName + QLatin1String(".desktop"); | ||
47 | const QStringList desktopFileLocations = QStandardPaths::locateAll(QStandardPaths::ApplicationsLocation, desktopFile, QStandardPaths::LocateFile); | 53 | const QStringList desktopFileLocations = QStandardPaths::locateAll(QStandardPaths::ApplicationsLocation, desktopFile, QStandardPaths::LocateFile); | ||
48 | for (const QString &location : desktopFileLocations) { | 54 | for (const QString &location : desktopFileLocations) { | ||
49 | QSettings settings(location, QSettings::IniFormat); | 55 | QSettings settings(location, QSettings::IniFormat); | ||
50 | settings.beginGroup(QStringLiteral("Desktop Entry")); | 56 | settings.beginGroup(QStringLiteral("Desktop Entry")); | ||
Show All 15 Lines | |||||
66 | } | 72 | } | ||
67 | } | 73 | } | ||
68 | 74 | | |||
69 | ScreenChooserDialog::~ScreenChooserDialog() | 75 | ScreenChooserDialog::~ScreenChooserDialog() | ||
70 | { | 76 | { | ||
71 | delete m_dialog; | 77 | delete m_dialog; | ||
72 | } | 78 | } | ||
73 | 79 | | |||
80 | void ScreenChooserDialog::setSourceTypes(ScreenCastPortal::SourceTypes types) | ||||
81 | { | ||||
82 | m_dialog->screensTab->setEnabled(types & ScreenCastPortal::Monitor); | ||||
83 | m_dialog->windowsTab->setEnabled(types & ScreenCastPortal::Window); | ||||
84 | } | ||||
85 | | ||||
74 | QList<quint32> ScreenChooserDialog::selectedScreens() const | 86 | QList<quint32> ScreenChooserDialog::selectedScreens() const | ||
75 | { | 87 | { | ||
76 | return m_dialog->screenView->selectedScreens(); | 88 | return m_dialog->screenView->selectedScreens(); | ||
77 | } | 89 | } | ||
90 | | ||||
91 | QList<quint32> ScreenChooserDialog::selectedWindows() const | ||||
92 | { | ||||
93 | const auto idxs = m_dialog->windowsView->selectionModel()->selectedIndexes(); | ||||
94 | | ||||
95 | QList<quint32> ret; | ||||
96 | ret.reserve(idxs.count()); | ||||
97 | for (const auto &idx : idxs) { | ||||
98 | ret += idx.data(KWayland::Client::PlasmaWindowModel::InternalId).toUInt(); | ||||
99 | } | ||||
100 | return ret; | ||||
101 | } |