screenchooserdialog.cpp 2.79 KB
Newer Older
Jan Grulich's avatar
Jan Grulich committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * 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 "screenchooserdialog.h"
#include "ui_screenchooserdialog.h"

24
#include <KLocalizedString>
Jan Grulich's avatar
Jan Grulich committed
25
#include <QPushButton>
26
27
#include <QStandardPaths>
#include <QSettings>
Jan Grulich's avatar
Jan Grulich committed
28

29
ScreenChooserDialog::ScreenChooserDialog(const QString &appName, bool multiple, QDialog *parent, Qt::WindowFlags flags)
Jan Grulich's avatar
Jan Grulich committed
30
31
32
33
34
    : QDialog(parent, flags)
    , m_dialog(new Ui::ScreenChooserDialog)
{
    m_dialog->setupUi(this);

35
36
    if (multiple) {
        m_dialog->screenView->setSelectionMode(QAbstractItemView::ExtendedSelection);
Jan Grulich's avatar
Jan Grulich committed
37
38
39
40
41
42
43
    }

    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);

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

    QString applicationName;
    const QString desktopFile = appName + QLatin1String(".desktop");
47
    const QStringList desktopFileLocations = QStandardPaths::locateAll(QStandardPaths::ApplicationsLocation, desktopFile, QStandardPaths::LocateFile);
Jan Grulich's avatar
Jan Grulich committed
48
    for (const QString &location : desktopFileLocations) {
49
        QSettings settings(location, QSettings::IniFormat);
Laurent Montel's avatar
Laurent Montel committed
50
51
52
        settings.beginGroup(QStringLiteral("Desktop Entry"));
        if (settings.contains(QStringLiteral("X-GNOME-FullName"))) {
            applicationName = settings.value(QStringLiteral("X-GNOME-FullName")).toString();
53
        } else {
Laurent Montel's avatar
Laurent Montel committed
54
            applicationName = settings.value(QStringLiteral("Name")).toString();
55
56
57
58
59
        }

        if (!applicationName.isEmpty()) {
            break;
        }
60
61
62
63
64
    }

    if (applicationName.isEmpty()) {
        setWindowTitle(i18n("Select screen to share with the requesting application"));
    } else {
Yuri Chornoivan's avatar
Yuri Chornoivan committed
65
        setWindowTitle(i18n("Select screen to share with %1", applicationName));
66
    }
Jan Grulich's avatar
Jan Grulich committed
67
68
69
70
71
72
73
74
75
}

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

QList<quint32> ScreenChooserDialog::selectedScreens() const
{
76
    return m_dialog->screenView->selectedScreens();
Jan Grulich's avatar
Jan Grulich committed
77
}