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())-
59 return xdgCurrentDesktop.toUpper(); // KDE, GNOME, UNITY, LXDE, MATE, XFCE...-
60-
61 // Classic fallbacks-
62 if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION"))-
63 return QByteArrayLiteral("KDE");-
64 if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID"))-
65 return QByteArrayLiteral("GNOME");-
66-
67 // Fallback to checking $DESKTOP_SESSION (unreliable)-
68 const QByteArray desktopSession = qgetenv("DESKTOP_SESSION");-
69 if (desktopSession == "gnome")-
70 return QByteArrayLiteral("GNOME");-
71 if (desktopSession == "xfce")-
72 return QByteArrayLiteral("XFCE");-
73-
74 return QByteArrayLiteral("UNKNOWN");-
75}-
76-
77static inline bool checkExecutable(const QString &candidate, QString *result)-
78{-
79 *result = QStandardPaths::findExecutable(candidate);-
80 return !result->isEmpty();-
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))
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(QStringLiteralQLatin1String(" 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 + QStringLiteralQLatin1String(" &")));-
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;-
137}-
138-
139bool QGenericUnixServices::openUrl(const QUrl &url)-
140{-
141 if (url.scheme() == QLatin1String("mailto"))-
142 return openDocument(url);-
143-
144 if (m_webBrowser.isEmpty() && !detectWebBrowser(desktopEnvironment(), true, &m_webBrowser)) {-
145 qWarning("Unable to detect a web browser to launch '%s'", qPrintable(url.toString()));-
146 return false;-
147 }-
148 return launch(m_webBrowser, url);-
149}-
150-
151bool QGenericUnixServices::openDocument(const QUrl &url)-
152{-
153 if (m_documentLauncher.isEmpty() && !detectWebBrowser(desktopEnvironment(), false, &m_documentLauncher)) {-
154 qWarning("Unable to detect a launcher for '%s'", qPrintable(url.toString()));-
155 return false;-
156 }-
157 return launch(m_documentLauncher, url);-
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