Changeset View
Changeset View
Standalone View
Standalone View
src/screenchooserdialog.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright © 2018 Red Hat, Inc | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This library is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Lesser General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Lesser General Public | ||||
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | * | ||||
17 | * Authors: | ||||
18 | * Jan Grulich <jgrulich@redhat.com> | ||||
19 | */ | ||||
20 | | ||||
21 | #include "screenchooserdialog.h" | ||||
22 | #include "ui_screenchooserdialog.h" | ||||
23 | #include "screencast.h" | ||||
24 | | ||||
25 | #include <QLoggingCategory> | ||||
26 | #include <QSettings> | ||||
27 | #include <QStandardPaths> | ||||
28 | #include <QPushButton> | ||||
29 | | ||||
30 | Q_LOGGING_CATEGORY(XdgDesktopPortalKdeScreenChooserDialog, "xdp-kde-screen-chooser-dialog") | ||||
31 | | ||||
32 | ScreenChooserDialog::ScreenChooserDialog(const QMap<quint32, ScreenCastPortalOutput> &screens, bool multiple, QDialog *parent, Qt::WindowFlags flags) | ||||
33 | : QDialog(parent, flags) | ||||
34 | , m_dialog(new Ui::ScreenChooserDialog) | ||||
35 | { | ||||
36 | m_dialog->setupUi(this); | ||||
37 | | ||||
38 | QMapIterator<quint32, ScreenCastPortalOutput> it(screens); | ||||
39 | while (it.hasNext()) { | ||||
40 | it.next(); | ||||
41 | QListWidgetItem *widgetItem = new QListWidgetItem(m_dialog->screenView); | ||||
42 | widgetItem->setData(Qt::UserRole, it.key()); | ||||
43 | if (it.value().outputType == ScreenCastPortalOutput::Laptop) { | ||||
44 | widgetItem->setIcon(QIcon::fromTheme("computer-laptop")); | ||||
45 | widgetItem->setText(i18n("Laptop screen\nModel: %1").arg(it.value().model)); | ||||
46 | } else if (it.value().outputType == ScreenCastPortalOutput::Monitor) { | ||||
47 | widgetItem->setIcon(QIcon::fromTheme("video-display")); | ||||
48 | widgetItem->setText(i18n("Manufacturer: %1\nModel: %2").arg(it.value().manufacturer).arg(it.value().model)); | ||||
49 | } else { | ||||
50 | widgetItem->setIcon(QIcon::fromTheme("video-television")); | ||||
51 | widgetItem->setText(i18n("Manufacturer: %1\nModel: %2").arg(it.value().manufacturer).arg(it.value().model)); | ||||
52 | } | ||||
53 | } | ||||
54 | | ||||
55 | m_dialog->screenView->setItemSelected(m_dialog->screenView->itemAt(0, 0), true); | ||||
56 | | ||||
57 | connect(m_dialog->buttonBox, &QDialogButtonBox::accepted, this, &ScreenChooserDialog::accept); | ||||
58 | connect(m_dialog->buttonBox, &QDialogButtonBox::rejected, this, &ScreenChooserDialog::reject); | ||||
59 | connect(m_dialog->screenView, &QListWidget::itemDoubleClicked, this, &ScreenChooserDialog::accept); | ||||
60 | | ||||
61 | if (multiple) { | ||||
62 | m_dialog->screenView->setSelectionMode(QAbstractItemView::ExtendedSelection); | ||||
63 | } | ||||
64 | | ||||
65 | m_dialog->buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("Share")); | ||||
66 | setWindowTitle(i18n("Select screen to share")); | ||||
67 | } | ||||
68 | | ||||
69 | ScreenChooserDialog::~ScreenChooserDialog() | ||||
70 | { | ||||
71 | delete m_dialog; | ||||
72 | } | ||||
73 | | ||||
74 | QList<quint32> ScreenChooserDialog::selectedScreens() const | ||||
75 | { | ||||
76 | QList<quint32> selectedScreens; | ||||
77 | | ||||
78 | foreach (QListWidgetItem *item, m_dialog->screenView->selectedItems()) { | ||||
79 | selectedScreens << item->data(Qt::UserRole).toUInt(); | ||||
80 | } | ||||
81 | | ||||
82 | return selectedScreens; | ||||
83 | } |