remotedesktopdialog.cpp 3.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * 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 "remotedesktopdialog.h"
#include "ui_remotedesktopdialog.h"

#include <QLoggingCategory>
#include <QStandardPaths>
#include <QSettings>
#include <QPushButton>

Q_LOGGING_CATEGORY(XdgDesktopPortalKdeRemoteDesktopDialog, "xdp-kde-remote-desktop-dialog")

RemoteDesktopDialog::RemoteDesktopDialog(const QString &appName, RemoteDesktopPortal::DeviceTypes deviceTypes, bool screenSharingEnabled,
                                         bool multiple, QDialog *parent, Qt::WindowFlags flags)
    : QDialog(parent, flags)
    , m_dialog(new Ui::RemoteDesktopDialog)
{
    m_dialog->setupUi(this);

    m_dialog->screenCastWidget->setVisible(screenSharingEnabled);
    if (screenSharingEnabled) {
        connect(m_dialog->screenCastWidget, &QListWidget::itemDoubleClicked, this, &RemoteDesktopDialog::accept);

        if (multiple) {
            m_dialog->screenCastWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
        }
    }

47
48
49
    m_dialog->keyboardCheckbox->setChecked(deviceTypes.testFlag(RemoteDesktopPortal::Keyboard));
    m_dialog->pointerCheckbox->setChecked(deviceTypes.testFlag(RemoteDesktopPortal::Pointer));
    m_dialog->touchScreenCheckbox->setChecked(deviceTypes.testFlag(RemoteDesktopPortal::TouchScreen));
50
51
52
53
54
55
56
57

    connect(m_dialog->buttonBox, &QDialogButtonBox::accepted, this, &RemoteDesktopDialog::accept);
    connect(m_dialog->buttonBox, &QDialogButtonBox::rejected, this, &RemoteDesktopDialog::reject);

    m_dialog->buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("Share"));

    QString applicationName;
    const QString desktopFile = appName + QLatin1String(".desktop");
58
    const QStringList desktopFileLocations = QStandardPaths::locateAll(QStandardPaths::ApplicationsLocation, desktopFile, QStandardPaths::LocateFile);
Jan Grulich's avatar
Jan Grulich committed
59
    for (const QString &location : desktopFileLocations) {
60
        QSettings settings(location, QSettings::IniFormat);
Laurent Montel's avatar
Laurent Montel committed
61
62
63
        settings.beginGroup(QStringLiteral("Desktop Entry"));
        if (settings.contains(QStringLiteral("X-GNOME-FullName"))) {
            applicationName = settings.value(QStringLiteral("X-GNOME-FullName")).toString();
64
        } else {
Laurent Montel's avatar
Laurent Montel committed
65
            applicationName = settings.value(QStringLiteral("Name")).toString();
66
67
68
69
70
        }

        if (!applicationName.isEmpty()) {
            break;
        }
71
72
73
74
75
    }

    if (applicationName.isEmpty()) {
        setWindowTitle(i18n("Select what to share with the requesting application"));
    } else {
Yuri Chornoivan's avatar
Yuri Chornoivan committed
76
        setWindowTitle(i18n("Select what to share with %1", applicationName));
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    }
}

RemoteDesktopDialog::~RemoteDesktopDialog()
{
    delete m_dialog;
}

QList<quint32> RemoteDesktopDialog::selectedScreens() const
{
    return m_dialog->screenCastWidget->selectedScreens();
}

RemoteDesktopPortal::DeviceTypes RemoteDesktopDialog::deviceTypes() const
{
92
93
94
95
96
97
98
99
100
    RemoteDesktopPortal::DeviceTypes types = RemoteDesktopPortal::None;
    if (m_dialog->keyboardCheckbox->isChecked())
        types |= RemoteDesktopPortal::Keyboard;
    if (m_dialog->pointerCheckbox->isChecked())
        types |= RemoteDesktopPortal::Pointer;
    if (m_dialog->touchScreenCheckbox->isChecked())
        types |= RemoteDesktopPortal::TouchScreen;

    return types;
101
}