Qt 4.8
Functions
qdesktopservices_mac.cpp File Reference
#include <qprocess.h>
#include <qstringlist.h>
#include <qdir.h>
#include <qurl.h>
#include <private/qcore_mac_p.h>
#include <qcoreapplication.h>
#include <ApplicationServices/ApplicationServices.h>

Go to the source code of this file.

Functions

static QString getFullPath (const FSRef &ref)
 
static bool launchWebBrowser (const QUrl &url)
 
static bool lsOpen (const QUrl &url)
 
static bool openDocument (const QUrl &file)
 
OSType translateLocation (QDesktopServices::StandardLocation type)
 

Function Documentation

◆ getFullPath()

static QString getFullPath ( const FSRef &  ref)
static

Definition at line 129 of file qdesktopservices_mac.cpp.

130 {
131  QByteArray ba(2048, 0);
132  if (FSRefMakePath(&ref, reinterpret_cast<UInt8 *>(ba.data()), ba.size()) == noErr)
134  return QString();
135 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString normalized(NormalizationForm mode) const Q_REQUIRED_RESULT
Returns the string in the given Unicode normalization mode.
Definition: qstring.cpp:6635
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302

◆ launchWebBrowser()

static bool launchWebBrowser ( const QUrl url)
static

Definition at line 112 of file qdesktopservices_mac.cpp.

113 {
114  return lsOpen(url);
115 }
static bool lsOpen(const QUrl &url)

◆ lsOpen()

static bool lsOpen ( const QUrl url)
static

Definition at line 99 of file qdesktopservices_mac.cpp.

Referenced by launchWebBrowser().

100 {
101  if (!url.isValid() || url.scheme().isEmpty())
102  return false;
103 
104  QCFType<CFURLRef> cfUrl = CFURLCreateWithString(0, QCFString(QString::fromLatin1(url.toEncoded())), 0);
105  if (cfUrl == 0)
106  return false;
107 
108  const OSStatus err = LSOpenCFURLRef(cfUrl, 0);
109  return (err == noErr);
110 }
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
signed long OSStatus
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
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
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

◆ openDocument()

static bool openDocument ( const QUrl file)
static

Definition at line 117 of file qdesktopservices_mac.cpp.

118 {
119  if (!file.isValid())
120  return false;
121 
122  // LSOpen does not work in this case, use QProcess open instead.
123  return QProcess::startDetached(QLatin1String("open"), QStringList() << file.toLocalFile());
124 }
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
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
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
Definition: qurl.cpp:6412

◆ translateLocation()

OSType translateLocation ( QDesktopServices::StandardLocation  type)

Definition at line 59 of file qdesktopservices_mac.cpp.

Referenced by getFullPath().

60 {
61  switch (type) {
63  return kDesktopFolderType; break;
64 
66  return kDocumentsFolderType; break;
67 
69  // There are at least two different font directories on the mac: /Library/Fonts and ~/Library/Fonts.
70  // To select a specific one we have to specify a different first parameter when calling FSFindFolder.
71  return kFontsFolderType; break;
72 
74  return kApplicationsFolderType; break;
75 
77  return kMusicDocumentsFolderType; break;
78 
80  return kMovieDocumentsFolderType; break;
81 
83  return kPictureDocumentsFolderType; break;
84 
86  return kTemporaryFolderType; break;
87 
89  return kApplicationSupportFolderType; break;
90 
92  return kCachedDataFolderType; break;
93 
94  default:
95  return kDesktopFolderType; break;
96  }
97 }
int type
Definition: qmetatype.cpp:239