OpenCoverage

qgenericunixservices.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/services/genericunix/qgenericunixservices.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the plugins of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qgenericunixservices_p.h"-
41-
42#include <QtCore/QStandardPaths>-
43#include <QtCore/QProcess>-
44#include <QtCore/QUrl>-
45#include <QtCore/QDebug>-
46-
47#include <stdlib.h>-
48-
49QT_BEGIN_NAMESPACE-
50-
51#ifndef QT_NO_MULTIPROCESS-
52-
53enum { debug = 0 };-
54-
55static inline QByteArray detectDesktopEnvironment()-
56{-
57 const QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP");-
58 if (!xdgCurrentDesktop.isEmpty())
!xdgCurrentDesktop.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 33 times by 5 tests
Evaluated by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
0-33
59 return xdgCurrentDesktop.toUpper(); // KDE, GNOME, UNITY, LXDE, MATE, XFCE...
never executed: return xdgCurrentDesktop.toUpper();
0
60-
61 // Classic fallbacks-
62 if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION"))
!qEnvironmentV...FULL_SESSION")Description
TRUEnever evaluated
FALSEevaluated 33 times by 5 tests
Evaluated by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
0-33
63 return QByteArrayLiteral("KDE");
never executed: return ([]() -> QByteArray { enum { Size = sizeof("KDE") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "KDE" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }());
never executed: return ba;
0
64 if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID"))
!qEnvironmentV...P_SESSION_ID")Description
TRUEnever evaluated
FALSEevaluated 33 times by 5 tests
Evaluated by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
0-33
65 return QByteArrayLiteral("GNOME");
never executed: return ([]() -> QByteArray { enum { Size = sizeof("GNOME") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GNOME" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }());
never executed: return ba;
0
66-
67 // Fallback to checking $DESKTOP_SESSION (unreliable)-
68 const QByteArray desktopSession = qgetenv("DESKTOP_SESSION");-
69 if (desktopSession == "gnome")
desktopSession == "gnome"Description
TRUEnever evaluated
FALSEevaluated 33 times by 5 tests
Evaluated by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
0-33
70 return QByteArrayLiteral("GNOME");
never executed: return ([]() -> QByteArray { enum { Size = sizeof("GNOME") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GNOME" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }());
never executed: return ba;
0
71 if (desktopSession == "xfce")
desktopSession == "xfce"Description
TRUEnever evaluated
FALSEevaluated 33 times by 5 tests
Evaluated by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
0-33
72 return QByteArrayLiteral("XFCE");
never executed: return ([]() -> QByteArray { enum { Size = sizeof("XFCE") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "XFCE" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }());
never executed: return ba;
0
73-
74 return QByteArrayLiteral("UNKNOWN");
executed 33 times by 5 tests: return ([]() -> QByteArray { enum { Size = sizeof("UNKNOWN") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "UNKNOWN" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }());
Executed by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
executed 33 times by 5 tests: return ba;
Executed by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
33
75}-
76-
77static inline bool checkExecutable(const QString &candidate, QString *result)-
78{-
79 *result = QStandardPaths::findExecutable(candidate);-
80 return !result->isEmpty();
never executed: return !result->isEmpty();
0
81}-
82-
83static inline bool detectWebBrowser(const QByteArray &desktop,-
84 bool checkBrowserVariable,-
85 QString *browser)-
86{-
87 const char *browsers[] = {"google-chrome", "firefox", "mozilla", "opera"};-
88-
89 browser->clear();-
90 if (checkExecutable(QStringLiteral("xdg-open"), browser))
never executed: return qstring_literal_temp;
checkExecutabl...}()), browser)Description
TRUEnever evaluated
FALSEnever evaluated
0
91 return true;
never executed: return true;
0
92-
93 if (checkBrowserVariable) {
checkBrowserVariableDescription
TRUEnever evaluated
FALSEnever evaluated
0
94 QByteArray browserVariable = qgetenv("DEFAULT_BROWSER");-
95 if (browserVariable.isEmpty())
browserVariable.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
96 browserVariable = qgetenv("BROWSER");
never executed: browserVariable = qgetenv("BROWSER");
0
97 if (!browserVariable.isEmpty() && checkExecutable(QString::fromLocal8Bit(browserVariable), browser))
!browserVariable.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
checkExecutabl...ble), browser)Description
TRUEnever evaluated
FALSEnever evaluated
0
98 return true;
never executed: return true;
0
99 }
never executed: end of block
0
100-
101 if (desktop == QByteArray("KDE")) {
desktop == QByteArray("KDE")Description
TRUEnever evaluated
FALSEnever evaluated
0
102 // Konqueror launcher-
103 if (checkExecutable(QStringLiteral("kfmclient"), browser)) {
never executed: return qstring_literal_temp;
checkExecutabl...}()), browser)Description
TRUEnever evaluated
FALSEnever evaluated
0
104 browser->append(QLatin1String(" exec"));-
105 return true;
never executed: return true;
0
106 }-
107 } else if (desktop == QByteArray("GNOME")) {
never executed: end of block
desktop == QByteArray("GNOME")Description
TRUEnever evaluated
FALSEnever evaluated
0
108 if (checkExecutable(QStringLiteral("gnome-open"), browser))
never executed: return qstring_literal_temp;
checkExecutabl...}()), browser)Description
TRUEnever evaluated
FALSEnever evaluated
0
109 return true;
never executed: return true;
0
110 }
never executed: end of block
0
111-
112 for (size_t i = 0; i < sizeof(browsers)/sizeof(char *); ++i)
i < sizeof(bro...sizeof(char *)Description
TRUEnever evaluated
FALSEnever evaluated
0
113 if (checkExecutable(QLatin1String(browsers[i]), browser))
checkExecutabl...[i]), browser)Description
TRUEnever evaluated
FALSEnever evaluated
0
114 return true;
never executed: return true;
0
115 return false;
never executed: return false;
0
116}-
117-
118static inline bool launch(const QString &launcher, const QUrl &url)-
119{-
120 const QString command = launcher + QLatin1Char(' ') + QLatin1String(url.toEncoded());-
121 if (debug)
debugDescription
TRUEnever evaluated
FALSEnever evaluated
0
122 qDebug("Launching %s", qPrintable(command));
never executed: QMessageLogger(__FILE__, 122, __PRETTY_FUNCTION__).debug("Launching %s", QString(command).toLocal8Bit().constData());
0
123#if defined(QT_NO_PROCESS)-
124 const bool ok = ::system(qPrintable(command + QLatin1String(" &")));-
125#else-
126 const bool ok = QProcess::startDetached(command);-
127#endif-
128 if (!ok)
!okDescription
TRUEnever evaluated
FALSEnever evaluated
0
129 qWarning("Launch failed (%s)", qPrintable(command));
never executed: QMessageLogger(__FILE__, 129, __PRETTY_FUNCTION__).warning("Launch failed (%s)", QString(command).toLocal8Bit().constData());
0
130 return ok;
never executed: return ok;
0
131}-
132-
133QByteArray QGenericUnixServices::desktopEnvironment() const-
134{-
135 static const QByteArray result = detectDesktopEnvironment();-
136 return result;
executed 4200 times by 125 tests: return result;
Executed by:
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QComplexText
  • tst_QCssParser
  • tst_QDataWidgetMapper
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDialogButtonBox
  • tst_QDockWidget
  • tst_QDoubleSpinBox
  • tst_QErrorMessage
  • tst_QFileDialog2
  • ...
4200
137}-
138-
139bool QGenericUnixServices::openUrl(const QUrl &url)-
140{-
141 if (url.scheme() == QLatin1String("mailto"))
url.scheme() =...ring("mailto")Description
TRUEnever evaluated
FALSEnever evaluated
0
142 return openDocument(url);
never executed: return openDocument(url);
0
143-
144 if (m_webBrowser.isEmpty() && !detectWebBrowser(desktopEnvironment(), true, &m_webBrowser)) {
m_webBrowser.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!detectWebBrow...&m_webBrowser)Description
TRUEnever evaluated
FALSEnever evaluated
0
145 qWarning("Unable to detect a web browser to launch '%s'", qPrintable(url.toString()));-
146 return false;
never executed: return false;
0
147 }-
148 return launch(m_webBrowser, url);
never executed: return launch(m_webBrowser, url);
0
149}-
150-
151bool QGenericUnixServices::openDocument(const QUrl &url)-
152{-
153 if (m_documentLauncher.isEmpty() && !detectWebBrowser(desktopEnvironment(), false, &m_documentLauncher)) {
m_documentLauncher.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!detectWebBrow...umentLauncher)Description
TRUEnever evaluated
FALSEnever evaluated
0
154 qWarning("Unable to detect a launcher for '%s'", qPrintable(url.toString()));-
155 return false;
never executed: return false;
0
156 }-
157 return launch(m_documentLauncher, url);
never executed: return launch(m_documentLauncher, url);
0
158}-
159-
160#else-
161QByteArray QGenericUnixServices::desktopEnvironment() const-
162{-
163 return QByteArrayLiteral("UNKNOWN");-
164}-
165-
166bool QGenericUnixServices::openUrl(const QUrl &url)-
167{-
168 qWarning("openUrl() not supported on this platform");-
169 return false;-
170}-
171-
172bool QGenericUnixServices::openDocument(const QUrl &url)-
173{-
174 qWarning("openDocument() not supported on this platform");-
175 return false;-
176}-
177-
178#endif // QT_NO_MULTIPROCESS-
179-
180QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9