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) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the plugins of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qgenericunixservices_p.h"-
35-
36#include <QtCore/QStandardPaths>-
37#include <QtCore/QProcess>-
38#include <QtCore/QUrl>-
39#include <QtCore/QDebug>-
40-
41#include <stdlib.h>-
42-
43QT_BEGIN_NAMESPACE-
44-
45enum { debug = 0 };-
46-
47static inline QByteArray detectDesktopEnvironment()-
48{-
49 const QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP");-
50 if (!xdgCurrentDesktop.isEmpty())
!xdgCurrentDesktop.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 28 times by 5 tests
Evaluated by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
0-28
51 return xdgCurrentDesktop.toUpper(); // KDE, GNOME, UNITY, LXDE, MATE, XFCE...
never executed: return xdgCurrentDesktop.toUpper();
0
52-
53 // Classic fallbacks-
54 if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION"))
!qEnvironmentV...FULL_SESSION")Description
TRUEnever evaluated
FALSEevaluated 28 times by 5 tests
Evaluated by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
0-28
55 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
56 if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID"))
!qEnvironmentV...P_SESSION_ID")Description
TRUEnever evaluated
FALSEevaluated 28 times by 5 tests
Evaluated by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
0-28
57 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
58-
59 // Fallback to checking $DESKTOP_SESSION (unreliable)-
60 const QByteArray desktopSession = qgetenv("DESKTOP_SESSION");-
61 if (desktopSession == "gnome")
desktopSession == "gnome"Description
TRUEnever evaluated
FALSEevaluated 28 times by 5 tests
Evaluated by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
0-28
62 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
63 if (desktopSession == "xfce")
desktopSession == "xfce"Description
TRUEnever evaluated
FALSEevaluated 28 times by 5 tests
Evaluated by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
0-28
64 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
65-
66 return QByteArrayLiteral("UNKNOWN");
executed 28 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 28 times by 5 tests: return ba;
Executed by:
  • tst_QApplication
  • tst_QGuiApplication
  • tst_qapplication - unknown status
  • tst_qprocess - unknown status
  • tst_selftests - unknown status
28
67}-
68-
69static inline bool checkExecutable(const QString &candidate, QString *result)-
70{-
71 *result = QStandardPaths::findExecutable(candidate);-
72 return !result->isEmpty();
never executed: return !result->isEmpty();
0
73}-
74-
75static inline bool detectWebBrowser(const QByteArray &desktop,-
76 bool checkBrowserVariable,-
77 QString *browser)-
78{-
79 const char *browsers[] = {"google-chrome", "firefox", "mozilla", "opera"};-
80-
81 browser->clear();-
82 if (checkExecutable(QStringLiteral("xdg-open"), browser))
never executed: return qstring_literal_temp;
checkExecutabl...}()), browser)Description
TRUEnever evaluated
FALSEnever evaluated
0
83 return true;
never executed: return true;
0
84-
85 if (checkBrowserVariable) {
checkBrowserVariableDescription
TRUEnever evaluated
FALSEnever evaluated
0
86 QByteArray browserVariable = qgetenv("DEFAULT_BROWSER");-
87 if (browserVariable.isEmpty())
browserVariable.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
88 browserVariable = qgetenv("BROWSER");
never executed: browserVariable = qgetenv("BROWSER");
0
89 if (!browserVariable.isEmpty() && checkExecutable(QString::fromLocal8Bit(browserVariable), browser))
!browserVariable.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
checkExecutabl...ble), browser)Description
TRUEnever evaluated
FALSEnever evaluated
0
90 return true;
never executed: return true;
0
91 }
never executed: end of block
0
92-
93 if (desktop == QByteArray("KDE")) {
desktop == QByteArray("KDE")Description
TRUEnever evaluated
FALSEnever evaluated
0
94 // Konqueror launcher-
95 if (checkExecutable(QStringLiteral("kfmclient"), browser)) {
never executed: return qstring_literal_temp;
checkExecutabl...}()), browser)Description
TRUEnever evaluated
FALSEnever evaluated
0
96 browser->append(QStringLiteral(" exec"));
never executed: return qstring_literal_temp;
0
97 return true;
never executed: return true;
0
98 }-
99 } else if (desktop == QByteArray("GNOME")) {
never executed: end of block
desktop == QByteArray("GNOME")Description
TRUEnever evaluated
FALSEnever evaluated
0
100 if (checkExecutable(QStringLiteral("gnome-open"), browser))
never executed: return qstring_literal_temp;
checkExecutabl...}()), browser)Description
TRUEnever evaluated
FALSEnever evaluated
0
101 return true;
never executed: return true;
0
102 }
never executed: end of block
0
103-
104 for (size_t i = 0; i < sizeof(browsers)/sizeof(char *); ++i)
i < sizeof(bro...sizeof(char *)Description
TRUEnever evaluated
FALSEnever evaluated
0
105 if (checkExecutable(QLatin1String(browsers[i]), browser))
checkExecutabl...[i]), browser)Description
TRUEnever evaluated
FALSEnever evaluated
0
106 return true;
never executed: return true;
0
107 return false;
never executed: return false;
0
108}-
109-
110static inline bool launch(const QString &launcher, const QUrl &url)-
111{-
112 const QString command = launcher + QLatin1Char(' ') + QLatin1String(url.toEncoded());-
113 if (debug)
debugDescription
TRUEnever evaluated
FALSEnever evaluated
0
114 qDebug("Launching %s", qPrintable(command));
never executed: QMessageLogger(__FILE__, 114, __PRETTY_FUNCTION__).debug("Launching %s", QString(command).toLocal8Bit().constData());
0
115#if defined(QT_NO_PROCESS)-
116 const bool ok = ::system(qPrintable(command + QStringLiteral(" &")));-
117#else-
118 const bool ok = QProcess::startDetached(command);-
119#endif-
120 if (!ok)
!okDescription
TRUEnever evaluated
FALSEnever evaluated
0
121 qWarning("Launch failed (%s)", qPrintable(command));
never executed: QMessageLogger(__FILE__, 121, __PRETTY_FUNCTION__).warning("Launch failed (%s)", QString(command).toLocal8Bit().constData());
0
122 return ok;
never executed: return ok;
0
123}-
124-
125QByteArray QGenericUnixServices::desktopEnvironment() const-
126{-
127 static const QByteArray result = detectDesktopEnvironment();-
128 return result;
executed 10423 times by 126 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
  • ...
10423
129}-
130-
131bool QGenericUnixServices::openUrl(const QUrl &url)-
132{-
133 if (url.scheme() == QLatin1String("mailto"))
url.scheme() =...ring("mailto")Description
TRUEnever evaluated
FALSEnever evaluated
0
134 return openDocument(url);
never executed: return openDocument(url);
0
135-
136 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
137 qWarning("Unable to detect a web browser to launch '%s'", qPrintable(url.toString()));-
138 return false;
never executed: return false;
0
139 }-
140 return launch(m_webBrowser, url);
never executed: return launch(m_webBrowser, url);
0
141}-
142-
143bool QGenericUnixServices::openDocument(const QUrl &url)-
144{-
145 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
146 qWarning("Unable to detect a launcher for '%s'", qPrintable(url.toString()));-
147 return false;
never executed: return false;
0
148 }-
149 return launch(m_documentLauncher, url);
never executed: return launch(m_documentLauncher, url);
0
150}-
151-
152QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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