Qt 4.8
Functions
qdesktopservices_x11.cpp File Reference
#include "qdesktopservices.h"
#include <qprocess.h>
#include <qurl.h>
#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#include <private/qt_x11_p.h>
#include <qcoreapplication.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

static bool launch (const QUrl &url, const QString &client)
 
static bool launchWebBrowser (const QUrl &url)
 
static bool openDocument (const QUrl &url)
 

Function Documentation

◆ launch()

static bool launch ( const QUrl url,
const QString client 
)
inlinestatic

Definition at line 57 of file qdesktopservices_x11.cpp.

Referenced by launchWebBrowser(), and openDocument().

58 {
59 #if !defined(QT_NO_PROCESS)
61 #else
62  return (::system((client + QLatin1Char(' ') + QString::fromLatin1(url.toEncoded().constData())).toLocal8Bit().constData()) != -1);
63 #endif
64 }
static bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid=0)
Starts the program program with the arguments arguments in a new process, and detaches from it...
Definition: qprocess.cpp:2332
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ launchWebBrowser()

static bool launchWebBrowser ( const QUrl url)
static

Definition at line 95 of file qdesktopservices_x11.cpp.

96 {
97  if (!url.isValid())
98  return false;
99  if (url.scheme() == QLatin1String("mailto"))
100  return openDocument(url);
101 
102  if (launch(url, QLatin1String("xdg-open")))
103  return true;
104  if (launch(url, QString::fromLocal8Bit(getenv("DEFAULT_BROWSER"))))
105  return true;
106  if (launch(url, QString::fromLocal8Bit(getenv("BROWSER"))))
107  return true;
108 
109  // Use the X11->desktopEnvironment value if X11 is non-NULL,
110  // otherwise just attempt to launch command regardless of the desktop environment
111  if ((!X11 || (X11 && X11->desktopEnvironment == DE_GNOME)) && launch(url, QLatin1String("gnome-open"))) {
112  return true;
113  } else {
114  if ((!X11 || (X11 && X11->desktopEnvironment == DE_KDE)) && launch(url, QLatin1String("kfmclient openURL")))
115  return true;
116  }
117 
118  if (launch(url, QLatin1String("firefox")))
119  return true;
120  if (launch(url, QLatin1String("mozilla")))
121  return true;
122  if (launch(url, QLatin1String("netscape")))
123  return true;
124  if (launch(url, QLatin1String("opera")))
125  return true;
126  return false;
127 }
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
static bool openDocument(const QUrl &url)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define X11
Definition: qt_x11_p.h:724
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
static bool launch(const QUrl &url, const QString &client)

◆ openDocument()

static bool openDocument ( const QUrl url)
static

Definition at line 66 of file qdesktopservices_x11.cpp.

Referenced by launchWebBrowser().

67 {
68  if (!url.isValid())
69  return false;
70 
71  if (launch(url, QLatin1String("xdg-open")))
72  return true;
73 
74  // Use the X11->desktopEnvironment value if X11 is non-NULL,
75  // otherwise just attempt to launch command regardless of the desktop environment
76  if ((!X11 || (X11 && X11->desktopEnvironment == DE_GNOME)) && launch(url, QLatin1String("gnome-open"))) {
77  return true;
78  } else {
79  if ((!X11 || (X11 && X11->desktopEnvironment == DE_KDE)) && launch(url, QLatin1String("kfmclient exec")))
80  return true;
81  }
82 
83  if (launch(url, QLatin1String("firefox")))
84  return true;
85  if (launch(url, QLatin1String("mozilla")))
86  return true;
87  if (launch(url, QLatin1String("netscape")))
88  return true;
89  if (launch(url, QLatin1String("opera")))
90  return true;
91 
92  return false;
93 }
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define X11
Definition: qt_x11_p.h:724
static bool launch(const QUrl &url, const QString &client)