Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 995066dd authored by Jan Grulich's avatar Jan Grulich

Make separated widget with screens to be shared with remote desktop dialog

parent 760170e9
/*
* Copyright © 2018 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Jan Grulich <jgrulich@redhat.com>
*/
#include "screencastwidget.h"
#include "waylandintegration.h"
#include <KLocalizedString>
ScreenCastWidget::ScreenCastWidget(QWidget *parent)
: QListWidget(parent)
{
QMapIterator<quint32, WaylandIntegration::WaylandOutput> it(WaylandIntegration::screens());
while (it.hasNext()) {
it.next();
QListWidgetItem *widgetItem = new QListWidgetItem(this);
widgetItem->setData(Qt::UserRole, it.key());
if (it.value().outputType() == WaylandIntegration::WaylandOutput::Laptop) {
widgetItem->setIcon(QIcon::fromTheme("computer-laptop"));
widgetItem->setText(i18n("Laptop screen\nModel: %1", it.value().model()));
} else if (it.value().outputType() == WaylandIntegration::WaylandOutput::Monitor) {
widgetItem->setIcon(QIcon::fromTheme("video-display"));
widgetItem->setText(i18n("Manufacturer: %1\nModel: %2", it.value().manufacturer(), it.value().model()));
} else {
widgetItem->setIcon(QIcon::fromTheme("video-television"));
widgetItem->setText(i18n("Manufacturer: %1\nModel: %2", it.value().manufacturer(), it.value().model()));
}
}
setItemSelected(itemAt(0, 0), true);
}
ScreenCastWidget::~ScreenCastWidget()
{
}
QList<quint32> ScreenCastWidget::selectedScreens() const
{
QList<quint32> selectedScreens;
foreach (QListWidgetItem *item, selectedItems()) {
selectedScreens << item->data(Qt::UserRole).toUInt();
}
return selectedScreens;
}
/*
* Copyright © 2018 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Jan Grulich <jgrulich@redhat.com>
*/
#ifndef XDG_DESKTOP_PORTAL_KDE_SCREENCAST_WIDGET_H
#define XDG_DESKTOP_PORTAL_KDE_SCREENCAST_WIDGET_H
#include <QListWidget>
class ScreenCastWidget : public QListWidget
{
Q_OBJECT
public:
ScreenCastWidget(QWidget *parent = nullptr);
~ScreenCastWidget();
QList<quint32> selectedScreens() const;
};
#endif // XDG_DESKTOP_PORTAL_KDE_SCREENCAST_WIDGET_H
......@@ -20,49 +20,24 @@
#include "screenchooserdialog.h"
#include "ui_screenchooserdialog.h"
#include "screencast.h"
#include "waylandintegration.h"
#include <QLoggingCategory>
#include <QSettings>
#include <QStandardPaths>
#include <KLocalizedString>
#include <QPushButton>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeScreenChooserDialog, "xdp-kde-screen-chooser-dialog")
ScreenChooserDialog::ScreenChooserDialog(bool multiple, QDialog *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
, m_dialog(new Ui::ScreenChooserDialog)
{
m_dialog->setupUi(this);
QMapIterator<quint32, WaylandIntegration::WaylandOutput> it(WaylandIntegration::screens());
while (it.hasNext()) {
it.next();
QListWidgetItem *widgetItem = new QListWidgetItem(m_dialog->screenView);
widgetItem->setData(Qt::UserRole, it.key());
if (it.value().outputType() == WaylandIntegration::WaylandOutput::Laptop) {
widgetItem->setIcon(QIcon::fromTheme("computer-laptop"));
widgetItem->setText(i18n("Laptop screen\nModel: %1", it.value().model()));
} else if (it.value().outputType() == WaylandIntegration::WaylandOutput::Monitor) {
widgetItem->setIcon(QIcon::fromTheme("video-display"));
widgetItem->setText(i18n("Manufacturer: %1\nModel: %2", it.value().manufacturer(), it.value().model()));
} else {
widgetItem->setIcon(QIcon::fromTheme("video-television"));
widgetItem->setText(i18n("Manufacturer: %1\nModel: %2", it.value().manufacturer(), it.value().model()));
}
if (multiple) {
m_dialog->screenView->setSelectionMode(QAbstractItemView::ExtendedSelection);
}
m_dialog->screenView->setItemSelected(m_dialog->screenView->itemAt(0, 0), true);
connect(m_dialog->buttonBox, &QDialogButtonBox::accepted, this, &ScreenChooserDialog::accept);
connect(m_dialog->buttonBox, &QDialogButtonBox::rejected, this, &ScreenChooserDialog::reject);
connect(m_dialog->screenView, &QListWidget::itemDoubleClicked, this, &ScreenChooserDialog::accept);
if (multiple) {
m_dialog->screenView->setSelectionMode(QAbstractItemView::ExtendedSelection);
}
m_dialog->buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("Share"));
setWindowTitle(i18n("Select screen to share"));
}
......@@ -74,11 +49,5 @@ ScreenChooserDialog::~ScreenChooserDialog()
QList<quint32> ScreenChooserDialog::selectedScreens() const
{
QList<quint32> selectedScreens;
foreach (QListWidgetItem *item, m_dialog->screenView->selectedItems()) {
selectedScreens << item->data(Qt::UserRole).toUInt();
}
return selectedScreens;
return m_dialog->screenView->selectedScreens();
}
......@@ -21,7 +21,6 @@
#ifndef XDG_DESKTOP_PORTAL_KDE_SCREENCHOOSER_DIALOG_H
#define XDG_DESKTOP_PORTAL_KDE_SCREENCHOOSER_DIALOG_H
#include <QAbstractListModel>
#include <QDialog>
namespace Ui
......@@ -33,7 +32,7 @@ class ScreenChooserDialog : public QDialog
{
Q_OBJECT
public:
ScreenChooserDialog(bool multiple = false, QDialog *parent = nullptr, Qt::WindowFlags flags = {});
ScreenChooserDialog(bool multiple, QDialog *parent = nullptr, Qt::WindowFlags flags = {});
~ScreenChooserDialog();
QList<quint32> selectedScreens() const;
......
......@@ -18,7 +18,7 @@
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item row="1" column="0">
<widget class="QListWidget" name="screenView">
<widget class="ScreenCastWidget" name="screenView">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
......@@ -42,6 +42,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ScreenCastWidget</class>
<extends>QListWidget</extends>
<header>screencastwidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment