From: David Faure Date: Fri, 21 Oct 2011 18:12:01 +0000 (+0200) Subject: Move path information from QDesktopServices (gui) to QStandardPaths (core) X-Git-Tag: qt-v5.0.0-alpha1~3107 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=86558de34134f67cf3815a29612edc2d730f2ea2;p=profile%2Fivi%2Fqtbase.git Move path information from QDesktopServices (gui) to QStandardPaths (core) Change-Id: Ic596c21894d83b4dab0c3f5b1aed916ddd590f2f Reviewed-by: Thiago Macieira (Intel) --- diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index e411f8f..6d7a59d 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -23,6 +23,7 @@ HEADERS += \ io/qtemporaryfile.h \ io/qresource_p.h \ io/qresource_iterator_p.h \ + io/qstandardpaths.h \ io/qurl.h \ io/qurltlds_p.h \ io/qtldurl_p.h \ @@ -56,6 +57,7 @@ SOURCES += \ io/qtemporaryfile.cpp \ io/qresource.cpp \ io/qresource_iterator.cpp \ + io/qstandardpaths.cpp \ io/qurl.cpp \ io/qsettings.cpp \ io/qfsfileengine.cpp \ @@ -75,6 +77,7 @@ win32 { SOURCES += io/qwindowspipewriter.cpp SOURCES += io/qfilesystemengine_win.cpp SOURCES += io/qfilesystemiterator_win.cpp + SOURCES += io/qstandardpaths_win.cpp } else:unix { SOURCES += io/qfsfileengine_unix.cpp symbian { @@ -91,6 +94,11 @@ win32 { SOURCES += io/qfilesystemengine_mac.cpp SOURCES += io/qsettings_mac.cpp io/qfilesystemwatcher_fsevents.cpp } + macx-*: { + SOURCES += io/qstandardpaths_mac.cpp + } else { + SOURCES += io/qstandardpaths_unix.cpp + } linux-*:!symbian { SOURCES += \ diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp new file mode 100644 index 0000000..e441a21 --- /dev/null +++ b/src/corelib/io/qstandardpaths.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qstandardpaths.h" + +#include +#include +#include +#include +#include + +#ifndef QT_NO_STANDARDPATHS + +QT_BEGIN_NAMESPACE + +/*! + \class QStandardPaths + \brief The QStandardPaths class provides methods for accessing standard paths. + \since 5.0 + + This class contains functions to query standard locations on the local + filesystem, for common tasks such as user-specific directories or system-wide + configuration directories. +*/ + +/*! + \enum QStandardPaths::StandardLocation + + This enum describes the different locations that can be queried using + methods such as QStandardPaths::storageLocation and QStandardPaths::displayName. + + \value DesktopLocation Returns the user's desktop directory. + \value DocumentsLocation Returns the user's document. + \value FontsLocation Returns the user's fonts. + \value ApplicationsLocation Returns the user's applications. + \value MusicLocation Returns the users music. + \value MoviesLocation Returns the user's movies. + \value PicturesLocation Returns the user's pictures. + \value TempLocation Returns the system's temporary directory. + \value HomeLocation Returns the user's home directory. + \value DataLocation Returns a directory location where persistent + application data can be stored. QCoreApplication::applicationName + and QCoreApplication::organizationName should work on all + platforms. + \value CacheLocation Returns a directory location where user-specific + non-essential (cached) data should be written. + + \sa storageLocation() displayName() +*/ + +/*! + \fn QString QStandardPaths::storageLocation(StandardLocation type) + + Returns the default system directory where files of \a type belong, or an empty string + if the location cannot be determined. + + \note The storage location returned can be a directory that does not exist; i.e., it + may need to be created by the system or the user. + + \note On Symbian OS, ApplicationsLocation always point /sys/bin folder on the same drive + with executable. FontsLocation always points to folder on ROM drive. Symbian OS does not + have desktop concept, DesktopLocation returns same path as DocumentsLocation. + Rest of the standard locations point to folder on same drive with executable, except + that if executable is in ROM the folder from C drive is returned. +*/ + +/*! + \fn QString QStandardPaths::displayName(StandardLocation type) + + Returns a localized display name for the given location \a type or + an empty QString if no relevant location can be found. +*/ + +QT_END_NAMESPACE + +#endif // QT_NO_STANDARDPATHS diff --git a/src/corelib/io/qstandardpaths.h b/src/corelib/io/qstandardpaths.h new file mode 100644 index 0000000..5b1bb82 --- /dev/null +++ b/src/corelib/io/qstandardpaths.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSTANDARDPATHS_H +#define QSTANDARDPATHS_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Core) + +#ifndef QT_NO_STANDARDPATHS + +class QStringList; + +class Q_CORE_EXPORT QStandardPaths +{ +public: + // Do not re-order, must match QDesktopServices + enum StandardLocation { + DesktopLocation, + DocumentsLocation, + FontsLocation, + ApplicationsLocation, + MusicLocation, + MoviesLocation, + PicturesLocation, + TempLocation, + HomeLocation, + DataLocation, + CacheLocation + }; + + static QString storageLocation(StandardLocation type); + static QString displayName(StandardLocation type); +}; + +#endif // QT_NO_STANDARDPATHS + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QSTANDARDPATHS_H diff --git a/src/corelib/io/qstandardpaths_mac.cpp b/src/corelib/io/qstandardpaths_mac.cpp new file mode 100644 index 0000000..b90cc7c --- /dev/null +++ b/src/corelib/io/qstandardpaths_mac.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT_NO_DESKTOPSERVICES + +#include "qstandardpaths.h" +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +/* + Translates a QStandardPaths::StandardLocation into the mac equivalent. +*/ +OSType translateLocation(QStandardPaths::StandardLocation type) +{ + switch (type) { + case QStandardPaths::DesktopLocation: + return kDesktopFolderType; + case QStandardPaths::DocumentsLocation: + return kDocumentsFolderType; + case QStandardPaths::FontsLocation: + // There are at least two different font directories on the mac: /Library/Fonts and ~/Library/Fonts. + // To select a specific one we have to specify a different first parameter when calling FSFindFolder. + return kFontsFolderType; + case QStandardPaths::ApplicationsLocation: + return kApplicationsFolderType; + case QStandardPaths::MusicLocation: + return kMusicDocumentsFolderType; + case QStandardPaths::MoviesLocation: + return kMovieDocumentsFolderType; + case QStandardPaths::PicturesLocation: + return kPictureDocumentsFolderType; + case QStandardPaths::TempLocation: + return kTemporaryFolderType; + case QStandardPaths::DataLocation: + return kApplicationSupportFolderType; + case QStandardPaths::CacheLocation: + return kCachedDataFolderType; + default: + return kDesktopFolderType; + } +} + +/* + Constructs a full unicode path from a FSRef. +*/ +static QString getFullPath(const FSRef &ref) +{ + QByteArray ba(2048, 0); + if (FSRefMakePath(&ref, reinterpret_cast(ba.data()), ba.size()) == noErr) + return QString::fromUtf8(ba).normalized(QString::NormalizationForm_C); + return QString(); +} + +QString QStandardPaths::storageLocation(StandardLocation type) +{ + if (type == HomeLocation) + return QDir::homePath(); + + if (type == TempLocation) + return QDir::tempPath(); + + short domain = kOnAppropriateDisk; + + if (type == DataLocation || type == CacheLocation) + domain = kUserDomain; + + // http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html + FSRef ref; + OSErr err = FSFindFolder(domain, translateLocation(type), false, &ref); + if (err) + return QString(); + + QString path = getFullPath(ref); + + if (type == DataLocation || type == CacheLocation) { + if (QCoreApplication::organizationName().isEmpty() == false) + path += QLatin1Char('/') + QCoreApplication::organizationName(); + if (QCoreApplication::applicationName().isEmpty() == false) + path += QLatin1Char('/') + QCoreApplication::applicationName(); + } + + return path; +} + +QString QStandardPaths::displayName(StandardLocation type) +{ + if (QStandardPaths::HomeLocation == type) + return QCoreApplication::translate("QStandardPaths", "Home"); + + FSRef ref; + OSErr err = FSFindFolder(kOnAppropriateDisk, translateLocation(type), false, &ref); + if (err) + return QString(); + + QCFString displayName; + err = LSCopyDisplayNameForRef(&ref, &displayName); + if (err) + return QString(); + + return static_cast(displayName); +} + +QT_END_NAMESPACE + +#endif // QT_NO_DESKTOPSERVICES diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp new file mode 100644 index 0000000..f0c5005 --- /dev/null +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qstandardpaths.h" +#include +#include +#include +#include +#include +#include +#include + +#ifndef QT_NO_STANDARDPATHS + +QT_BEGIN_NAMESPACE + +QString QStandardPaths::storageLocation(StandardLocation type) +{ + if (type == QStandardPaths::HomeLocation) + return QDir::homePath(); + if (type == QStandardPaths::TempLocation) + return QDir::tempPath(); + + // http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html + if (type == QStandardPaths::CacheLocation) { + QString xdgCacheHome = QLatin1String(qgetenv("XDG_CACHE_HOME")); + if (xdgCacheHome.isEmpty()) + xdgCacheHome = QDir::homePath() + QLatin1String("/.cache"); + xdgCacheHome += QLatin1Char('/') + QCoreApplication::organizationName() + + QLatin1Char('/') + QCoreApplication::applicationName(); + return xdgCacheHome; + } + + if (type == QStandardPaths::DataLocation) { + QString xdgDataHome = QLatin1String(qgetenv("XDG_DATA_HOME")); + if (xdgDataHome.isEmpty()) + xdgDataHome = QDir::homePath() + QLatin1String("/.local/share"); + xdgDataHome += QLatin1String("/data/") + + QCoreApplication::organizationName() + QLatin1Char('/') + + QCoreApplication::applicationName(); + return xdgDataHome; + } + + // http://www.freedesktop.org/wiki/Software/xdg-user-dirs + QString xdgConfigHome = QLatin1String(qgetenv("XDG_CONFIG_HOME")); + if (xdgConfigHome.isEmpty()) + xdgConfigHome = QDir::homePath() + QLatin1String("/.config"); + QFile file(xdgConfigHome + QLatin1String("/user-dirs.dirs")); + if (file.exists() && file.open(QIODevice::ReadOnly)) { + QHash lines; + QTextStream stream(&file); + // Only look for lines like: XDG_DESKTOP_DIR="$HOME/Desktop" + QRegExp exp(QLatin1String("^XDG_(.*)_DIR=(.*)$")); + while (!stream.atEnd()) { + QString line = stream.readLine(); + if (exp.indexIn(line) != -1) { + const QStringList lst = exp.capturedTexts(); + const QString key = lst.at(1); + QString value = lst.at(2); + if (value.length() > 2 + && value.startsWith(QLatin1Char('\"')) + && value.endsWith(QLatin1Char('\"'))) + value = value.mid(1, value.length() - 2); + // Store the key and value: "DESKTOP", "$HOME/Desktop" + lines[key] = value; + } + } + + QString key; + switch (type) { + case DesktopLocation: key = QLatin1String("DESKTOP"); break; + case DocumentsLocation: key = QLatin1String("DOCUMENTS"); break; + case PicturesLocation: key = QLatin1String("PICTURES"); break; + case MusicLocation: key = QLatin1String("MUSIC"); break; + case MoviesLocation: key = QLatin1String("VIDEOS"); break; + default: break; + } + if (!key.isEmpty() && lines.contains(key)) { + QString value = lines[key]; + // value can start with $HOME + if (value.startsWith(QLatin1String("$HOME"))) + value = QDir::homePath() + value.mid(5); + return value; + } + } + + QDir emptyDir; + QString path; + switch (type) { + case DesktopLocation: + path = QDir::homePath() + QLatin1String("/Desktop"); + break; + case DocumentsLocation: + path = QDir::homePath() + QLatin1String("/Documents"); + break; + case PicturesLocation: + path = QDir::homePath() + QLatin1String("/Pictures"); + break; + + case FontsLocation: + path = QDir::homePath() + QLatin1String("/.fonts"); + break; + + case MusicLocation: + path = QDir::homePath() + QLatin1String("/Music"); + break; + + case MoviesLocation: + path = QDir::homePath() + QLatin1String("/Videos"); + break; + + case ApplicationsLocation: + default: + break; + } + + return path; +} + +QString QStandardPaths::displayName(StandardLocation type) +{ + Q_UNUSED(type); + return QString(); +} + +QT_END_NAMESPACE + +#endif // QT_NO_STANDARDPATHS diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp new file mode 100644 index 0000000..7d7fbd0 --- /dev/null +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qstandardpaths.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#if !defined(Q_OS_WINCE) +# include +#else +# include +# if !defined(STANDARDSHELL_UI_MODEL) +# include +# endif +#endif + +#ifndef CSIDL_MYMUSIC +#define CSIDL_MYMUSIC 13 +#define CSIDL_MYVIDEO 14 +#endif + +#ifndef QT_NO_STANDARDPATHS + +QT_BEGIN_NAMESPACE + +QString QStandardPaths::storageLocation(StandardLocation type) +{ + QString result; + +#ifndef Q_OS_WINCE + QSystemLibrary library(QLatin1String("shell32")); +#else + QSystemLibrary library(QLatin1String("coredll")); +#endif // Q_OS_WINCE + typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL); + static GetSpecialFolderPath SHGetSpecialFolderPath = + (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW"); + if (!SHGetSpecialFolderPath) + return QString(); + + wchar_t path[MAX_PATH]; + + switch (type) { + case DataLocation: +#if defined Q_OS_WINCE + if (SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE)) +#else + if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE)) +#endif + result = QString::fromWCharArray(path); + if (!QCoreApplication::organizationName().isEmpty()) + result = result + QLatin1String("\\") + QCoreApplication::organizationName(); + if (!QCoreApplication::applicationName().isEmpty()) + result = result + QLatin1String("\\") + QCoreApplication::applicationName(); + break; + + case DesktopLocation: + if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, FALSE)) + result = QString::fromWCharArray(path); + break; + + case DocumentsLocation: + if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE)) + result = QString::fromWCharArray(path); + break; + + case FontsLocation: + if (SHGetSpecialFolderPath(0, path, CSIDL_FONTS, FALSE)) + result = QString::fromWCharArray(path); + break; + + case ApplicationsLocation: + if (SHGetSpecialFolderPath(0, path, CSIDL_PROGRAMS, FALSE)) + result = QString::fromWCharArray(path); + break; + + case MusicLocation: + if (SHGetSpecialFolderPath(0, path, CSIDL_MYMUSIC, FALSE)) + result = QString::fromWCharArray(path); + break; + + case MoviesLocation: + if (SHGetSpecialFolderPath(0, path, CSIDL_MYVIDEO, FALSE)) + result = QString::fromWCharArray(path); + break; + + case PicturesLocation: + if (SHGetSpecialFolderPath(0, path, CSIDL_MYPICTURES, FALSE)) + result = QString::fromWCharArray(path); + break; + + case CacheLocation: + // Although Microsoft has a Cache key it is a pointer to IE's cache, not a cache + // location for everyone. Most applications seem to be using a + // cache directory located in their AppData directory + return storageLocation(DataLocation) + QLatin1String("\\cache"); + + case QStandardPaths::HomeLocation: + result = QDir::homePath(); + break; + + case QStandardPaths::TempLocation: + result = QDir::tempPath(); + break; + + default: + break; + } + return result; +} + +QString QStandardPaths::displayName(StandardLocation type) +{ + Q_UNUSED(type); + return QString(); +} + +QT_END_NAMESPACE + +#endif // QT_NO_STANDARDPATHS diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp index 7e8195a..da3b498 100644 --- a/src/gui/util/qdesktopservices.cpp +++ b/src/gui/util/qdesktopservices.cpp @@ -47,6 +47,7 @@ #include "qdesktopservices_qpa.cpp" +#include #include #include #include @@ -269,28 +270,21 @@ void QDesktopServices::unsetUrlHandler(const QString &scheme) */ /*! - \fn QString QDesktopServices::storageLocation(StandardLocation type) - \since 4.4 - - Returns the default system directory where files of \a type belong, or an empty string - if the location cannot be determined. - - \note The storage location returned can be a directory that does not exist; i.e., it - may need to be created by the system or the user. - - \note On Symbian OS, ApplicationsLocation always point /sys/bin folder on the same drive - with executable. FontsLocation always points to folder on ROM drive. Symbian OS does not - have desktop concept, DesktopLocation returns same path as DocumentsLocation. - Rest of the standard locations point to folder on same drive with executable, except - that if executable is in ROM the folder from C drive is returned. + \deprecated Use QStandardPaths::storageLocation() */ +QString QDesktopServices::storageLocation(StandardLocation type) +{ + return QStandardPaths::storageLocation(static_cast(type)); +} -/*! - \fn QString QDesktopServices::displayName(StandardLocation type) - Returns a localized display name for the given location \a type or - an empty QString if no relevant location can be found. +/*! + \deprecated Use QStandardPaths::displayName() */ +QString QDesktopServices::displayName(StandardLocation type) +{ + return QStandardPaths::displayName(static_cast(type)); +} QT_END_NAMESPACE diff --git a/src/gui/util/qdesktopservices_mac.cpp b/src/gui/util/qdesktopservices_mac.cpp index d1711b0..f4b5263 100644 --- a/src/gui/util/qdesktopservices_mac.cpp +++ b/src/gui/util/qdesktopservices_mac.cpp @@ -45,7 +45,6 @@ #include #include #include -#include #include #include @@ -123,66 +122,6 @@ static bool openDocument(const QUrl &file) return QProcess::startDetached(QLatin1String("open"), QStringList() << file.toLocalFile()); } -/* - Constructs a full unicode path from a FSRef. -*/ -static QString getFullPath(const FSRef &ref) -{ - QByteArray ba(2048, 0); - if (FSRefMakePath(&ref, reinterpret_cast(ba.data()), ba.size()) == noErr) - return QString::fromUtf8(ba).normalized(QString::NormalizationForm_C); - return QString(); -} - -QString QDesktopServices::storageLocation(StandardLocation type) -{ - if (type == HomeLocation) - return QDir::homePath(); - - if (type == TempLocation) - return QDir::tempPath(); - - short domain = kOnAppropriateDisk; - - if (type == DataLocation || type == CacheLocation) - domain = kUserDomain; - - // http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html - FSRef ref; - OSErr err = FSFindFolder(domain, translateLocation(type), false, &ref); - if (err) - return QString(); - - QString path = getFullPath(ref); - - if (type == DataLocation || type == CacheLocation) { - if (QCoreApplication::organizationName().isEmpty() == false) - path += QLatin1Char('/') + QCoreApplication::organizationName(); - if (QCoreApplication::applicationName().isEmpty() == false) - path += QLatin1Char('/') + QCoreApplication::applicationName(); - } - - return path; -} - -QString QDesktopServices::displayName(StandardLocation type) -{ - if (QDesktopServices::HomeLocation == type) - return QObject::tr("Home"); - - FSRef ref; - OSErr err = FSFindFolder(kOnAppropriateDisk, translateLocation(type), false, &ref); - if (err) - return QString(); - - QCFString displayName; - err = LSCopyDisplayNameForRef(&ref, &displayName); - if (err) - return QString(); - - return static_cast(displayName); -} - QT_END_NAMESPACE #endif // QT_NO_DESKTOPSERVICES diff --git a/src/gui/util/qdesktopservices_qpa.cpp b/src/gui/util/qdesktopservices_qpa.cpp index 374b06b..c60cec8 100644 --- a/src/gui/util/qdesktopservices_qpa.cpp +++ b/src/gui/util/qdesktopservices_qpa.cpp @@ -39,8 +39,7 @@ ** ****************************************************************************/ -#include -#include +#include #include QT_BEGIN_NAMESPACE @@ -59,36 +58,4 @@ static bool openDocument(const QUrl &file) return false; } - -QString QDesktopServices::storageLocation(StandardLocation type) -{ - if (type == DataLocation) { - QString qwsDataHome = QLatin1String(qgetenv("QWS_DATA_HOME")); - if (qwsDataHome.isEmpty()) - qwsDataHome = QDir::homePath() + QLatin1String("/.qws/share"); - qwsDataHome += QLatin1String("/data/") - + QCoreApplication::organizationName() + QLatin1Char('/') - + QCoreApplication::applicationName(); - return qwsDataHome; - } - if (type == QDesktopServices::CacheLocation) { - QString qwsCacheHome = QLatin1String(qgetenv("QWS_CACHE_HOME")); - if (qwsCacheHome.isEmpty()) - qwsCacheHome = QDir::homePath() + QLatin1String("/.qws/cache/"); - qwsCacheHome += QCoreApplication::organizationName() + QLatin1Char('/') - + QCoreApplication::applicationName(); - return qwsCacheHome; - } - - qWarning("QDesktopServices::storageLocation %d not implemented", type); - return QString(); -} - -QString QDesktopServices::displayName(StandardLocation type) -{ - Q_UNUSED(type); - qWarning("QDesktopServices::displayName not implemented"); - return QString(); -} - QT_END_NAMESPACE diff --git a/src/gui/util/qdesktopservices_s60.cpp b/src/gui/util/qdesktopservices_s60.cpp index 41fc0f3..f4d8fe9 100644 --- a/src/gui/util/qdesktopservices_s60.cpp +++ b/src/gui/util/qdesktopservices_s60.cpp @@ -327,130 +327,5 @@ static bool openDocument(const QUrl &file) #endif //USE_SCHEMEHANDLER -// Common functions to all implementations - -static TDriveUnit exeDrive() -{ - RProcess me; - TFileName processFileName = me.FileName(); - TDriveUnit drive(processFileName); - return drive; -} - -static TDriveUnit writableExeDrive() -{ - TDriveUnit drive = exeDrive(); - if (drive.operator TInt() == EDriveZ) - return TDriveUnit(EDriveC); - return drive; -} - -static TPtrC writableDataRoot() -{ - TDriveUnit drive = exeDrive(); - switch (drive.operator TInt()){ - case EDriveC: - return PathInfo::PhoneMemoryRootPath(); - break; - case EDriveE: - return PathInfo::MemoryCardRootPath(); - break; - case EDriveZ: - // It is not possible to write on ROM drive -> - // return phone mem root path instead - return PathInfo::PhoneMemoryRootPath(); - break; - default: - return PathInfo::PhoneMemoryRootPath(); - break; - } -} - -QString QDesktopServices::storageLocation(StandardLocation type) -{ - TFileName path; - - switch (type) { - case DesktopLocation: - qWarning("No desktop concept in Symbian OS"); - // But lets still use some feasible default - path.Append(writableDataRoot()); - break; - case DocumentsLocation: - path.Append(writableDataRoot()); - break; - case FontsLocation: - path.Append(KFontsDir); - break; - case ApplicationsLocation: - path.Append(exeDrive().Name()); - path.Append(KSysBin); - break; - case MusicLocation: - path.Append(writableDataRoot()); - path.Append(PathInfo::SoundsPath()); - break; - case MoviesLocation: - path.Append(writableDataRoot()); - path.Append(PathInfo::VideosPath()); - break; - case PicturesLocation: - path.Append(writableDataRoot()); - path.Append(PathInfo::ImagesPath()); - break; - case TempLocation: - return QDir::tempPath(); - break; - case HomeLocation: - path.Append(writableDataRoot()); - //return QDir::homePath(); break; - break; - case DataLocation: - qt_s60GetRFs().PrivatePath(path); - path.Insert(0, writableExeDrive().Name()); - break; - case CacheLocation: - qt_s60GetRFs().PrivatePath(path); - path.Insert(0, writableExeDrive().Name()); - path.Append(KCacheSubDir); - break; - default: - // Lets use feasible default - path.Append(writableDataRoot()); - break; - } - - // Convert to cross-platform format and clean the path - QString nativePath = QString::fromUtf16(path.Ptr(), path.Length()); - QString qtPath = QDir::fromNativeSeparators(nativePath); - qtPath = QDir::cleanPath(qtPath); - - // Note: The storage location returned can be a directory that does not exist; - // i.e., it may need to be created by the system or the user. - return qtPath; -} - -typedef QString (*LocalizerFunc)(QString&); - -static QString defaultLocalizedDirectoryName(QString&) -{ - return QString(); -} - -QString QDesktopServices::displayName(StandardLocation type) -{ - static LocalizerFunc ptrLocalizerFunc = NULL; - - if (!ptrLocalizerFunc) { - ptrLocalizerFunc = reinterpret_cast - (qt_resolveS60PluginFunc(S60Plugin_LocalizedDirectoryName)); - if (!ptrLocalizerFunc) - ptrLocalizerFunc = &defaultLocalizedDirectoryName; - } - - QString rawPath = storageLocation(type); - return ptrLocalizerFunc(rawPath); -} - QT_END_NAMESPACE diff --git a/src/gui/util/qdesktopservices_win.cpp b/src/gui/util/qdesktopservices_win.cpp index b06b52e..8b120b4 100644 --- a/src/gui/util/qdesktopservices_win.cpp +++ b/src/gui/util/qdesktopservices_win.cpp @@ -172,92 +172,6 @@ static bool launchWebBrowser(const QUrl &url) return (returnValue > 32); } -QString QDesktopServices::storageLocation(StandardLocation type) -{ - QString result; - -#ifndef Q_OS_WINCE - QSystemLibrary library(QLatin1String("shell32")); -#else - QSystemLibrary library(QLatin1String("coredll")); -#endif // Q_OS_WINCE - typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL); - static GetSpecialFolderPath SHGetSpecialFolderPath = - (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW"); - if (!SHGetSpecialFolderPath) - return QString(); - - wchar_t path[MAX_PATH]; - - switch (type) { - case DataLocation: - if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE)) - result = QString::fromWCharArray(path); - if (!QCoreApplication::organizationName().isEmpty()) - result = result + QLatin1String("\\") + QCoreApplication::organizationName(); - if (!QCoreApplication::applicationName().isEmpty()) - result = result + QLatin1String("\\") + QCoreApplication::applicationName(); - break; - - case DesktopLocation: - if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, FALSE)) - result = QString::fromWCharArray(path); - break; - - case DocumentsLocation: - if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE)) - result = QString::fromWCharArray(path); - break; - - case FontsLocation: - if (SHGetSpecialFolderPath(0, path, CSIDL_FONTS, FALSE)) - result = QString::fromWCharArray(path); - break; - - case ApplicationsLocation: - if (SHGetSpecialFolderPath(0, path, CSIDL_PROGRAMS, FALSE)) - result = QString::fromWCharArray(path); - break; - - case MusicLocation: - if (SHGetSpecialFolderPath(0, path, CSIDL_MYMUSIC, FALSE)) - result = QString::fromWCharArray(path); - break; - - case MoviesLocation: - if (SHGetSpecialFolderPath(0, path, CSIDL_MYVIDEO, FALSE)) - result = QString::fromWCharArray(path); - break; - - case PicturesLocation: - if (SHGetSpecialFolderPath(0, path, CSIDL_MYPICTURES, FALSE)) - result = QString::fromWCharArray(path); - break; - - case CacheLocation: - // Although Microsoft has a Cache key it is a pointer to IE's cache, not a cache - // location for everyone. Most applications seem to be using a - // cache directory located in their AppData directory - return storageLocation(DataLocation) + QLatin1String("\\cache"); - - case QDesktopServices::HomeLocation: - return QDir::homePath(); break; - - case QDesktopServices::TempLocation: - return QDir::tempPath(); break; - - default: - break; - } - return result; -} - -QString QDesktopServices::displayName(StandardLocation type) -{ - Q_UNUSED(type); - return QString(); -} - QT_END_NAMESPACE #endif // QT_NO_DESKTOPSERVICES diff --git a/src/gui/util/qdesktopservices_x11.cpp b/src/gui/util/qdesktopservices_x11.cpp index fa40113..cf8dce3 100644 --- a/src/gui/util/qdesktopservices_x11.cpp +++ b/src/gui/util/qdesktopservices_x11.cpp @@ -126,117 +126,6 @@ static bool launchWebBrowser(const QUrl &url) return false; } - - -QString QDesktopServices::storageLocation(StandardLocation type) -{ - if (type == QDesktopServices::HomeLocation) - return QDir::homePath(); - if (type == QDesktopServices::TempLocation) - return QDir::tempPath(); - - // http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html - if (type == QDesktopServices::CacheLocation) { - QString xdgCacheHome = QLatin1String(qgetenv("XDG_CACHE_HOME")); - if (xdgCacheHome.isEmpty()) - xdgCacheHome = QDir::homePath() + QLatin1String("/.cache"); - xdgCacheHome += QLatin1Char('/') + QCoreApplication::organizationName() - + QLatin1Char('/') + QCoreApplication::applicationName(); - return xdgCacheHome; - } - - if (type == QDesktopServices::DataLocation) { - QString xdgDataHome = QLatin1String(qgetenv("XDG_DATA_HOME")); - if (xdgDataHome.isEmpty()) - xdgDataHome = QDir::homePath() + QLatin1String("/.local/share"); - xdgDataHome += QLatin1String("/data/") - + QCoreApplication::organizationName() + QLatin1Char('/') - + QCoreApplication::applicationName(); - return xdgDataHome; - } - - // http://www.freedesktop.org/wiki/Software/xdg-user-dirs - QString xdgConfigHome = QLatin1String(qgetenv("XDG_CONFIG_HOME")); - if (xdgConfigHome.isEmpty()) - xdgConfigHome = QDir::homePath() + QLatin1String("/.config"); - QFile file(xdgConfigHome + QLatin1String("/user-dirs.dirs")); - if (file.exists() && file.open(QIODevice::ReadOnly)) { - QHash lines; - QTextStream stream(&file); - // Only look for lines like: XDG_DESKTOP_DIR="$HOME/Desktop" - QRegExp exp(QLatin1String("^XDG_(.*)_DIR=(.*)$")); - while (!stream.atEnd()) { - QString line = stream.readLine(); - if (exp.indexIn(line) != -1) { - QStringList lst = exp.capturedTexts(); - QString key = lst.at(1); - QString value = lst.at(2); - if (value.length() > 2 - && value.startsWith(QLatin1Char('\"')) - && value.endsWith(QLatin1Char('\"'))) - value = value.mid(1, value.length() - 2); - // Store the key and value: "DESKTOP", "$HOME/Desktop" - lines[key] = value; - } - } - - QString key; - switch (type) { - case DesktopLocation: key = QLatin1String("DESKTOP"); break; - case DocumentsLocation: key = QLatin1String("DOCUMENTS"); break; - case PicturesLocation: key = QLatin1String("PICTURES"); break; - case MusicLocation: key = QLatin1String("MUSIC"); break; - case MoviesLocation: key = QLatin1String("VIDEOS"); break; - default: break; - } - if (!key.isEmpty() && lines.contains(key)) { - QString value = lines[key]; - // value can start with $HOME - if (value.startsWith(QLatin1String("$HOME"))) - value = QDir::homePath() + value.mid(5); - return value; - } - } - - QDir emptyDir; - QString path; - switch (type) { - case DesktopLocation: - path = QDir::homePath() + QLatin1String("/Desktop"); - break; - case DocumentsLocation: - path = QDir::homePath() + QLatin1String("/Documents"); - break; - case PicturesLocation: - path = QDir::homePath() + QLatin1String("/Pictures"); - break; - - case FontsLocation: - path = QDir::homePath() + QLatin1String("/.fonts"); - break; - - case MusicLocation: - path = QDir::homePath() + QLatin1String("/Music"); - break; - - case MoviesLocation: - path = QDir::homePath() + QLatin1String("/Videos"); - break; - - case ApplicationsLocation: - default: - break; - } - - return path; -} - -QString QDesktopServices::displayName(StandardLocation type) -{ - Q_UNUSED(type); - return QString(); -} - QT_END_NAMESPACE #endif // QT_NO_DESKTOPSERVICES