File indexing completed on 2024-11-10 04:55:32

0001 /*
0002     SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "utils.h"
0008 
0009 #include <kscreen/edid.h>
0010 
0011 #include <KLocalizedString>
0012 
0013 QString Utils::outputName(const KScreen::OutputPtr &output, bool shouldShowSerialNumber, bool shouldShowConnector)
0014 {
0015     return outputName(output.data(), shouldShowSerialNumber, shouldShowConnector);
0016 }
0017 
0018 QString Utils::outputName(const KScreen::Output *output, bool shouldShowSerialNumber, bool shouldShowConnector)
0019 {
0020     if (output->type() == KScreen::Output::Panel) {
0021         return i18nd("kscreen_common", "Built-in Screen");
0022     }
0023 
0024     if (output->edid()) {
0025         // The name will be "VendorName ModelName (ConnectorName)",
0026         // but some components may be empty.
0027         QString name;
0028         if (!(output->edid()->vendor().isEmpty())) {
0029             name = output->edid()->vendor() + QLatin1Char(' ');
0030         }
0031         if (!output->edid()->name().isEmpty()) {
0032             name += output->edid()->name() + QLatin1Char(' ');
0033         }
0034         if (!output->edid()->serial().isEmpty() && shouldShowSerialNumber) {
0035             name += output->edid()->serial() + QLatin1Char(' ');
0036         }
0037         if (shouldShowConnector) {
0038             name += output->name();
0039         }
0040         if (!name.trimmed().isEmpty()) {
0041             return name;
0042         }
0043     }
0044     return output->name();
0045 }
0046 
0047 QString Utils::sizeToString(const QSize &size)
0048 {
0049     return QStringLiteral("%1x%2").arg(size.width()).arg(size.height());
0050 }