diff options
author | David Faure <faure@kde.org> | 2011-10-21 20:12:01 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-23 00:56:31 +0200 |
commit | 86558de34134f67cf3815a29612edc2d730f2ea2 (patch) | |
tree | 868417b17bac24be1f17080680af0f614a98b9b6 /src/gui/util | |
parent | 4a788eb8313d7c089e3a59594fc6a5c9a7dd6499 (diff) |
Move path information from QDesktopServices (gui) to QStandardPaths (core)
Change-Id: Ic596c21894d83b4dab0c3f5b1aed916ddd590f2f
Reviewed-by: Thiago Macieira (Intel) <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui/util')
-rw-r--r-- | src/gui/util/qdesktopservices.cpp | 30 | ||||
-rw-r--r-- | src/gui/util/qdesktopservices_mac.cpp | 61 | ||||
-rw-r--r-- | src/gui/util/qdesktopservices_qpa.cpp | 35 | ||||
-rw-r--r-- | src/gui/util/qdesktopservices_s60.cpp | 125 | ||||
-rw-r--r-- | src/gui/util/qdesktopservices_win.cpp | 86 | ||||
-rw-r--r-- | src/gui/util/qdesktopservices_x11.cpp | 111 |
6 files changed, 13 insertions, 435 deletions
diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp index 7e8195afe9..da3b498729 100644 --- a/src/gui/util/qdesktopservices.cpp +++ b/src/gui/util/qdesktopservices.cpp @@ -47,6 +47,7 @@ #include "qdesktopservices_qpa.cpp" +#include <qstandardpaths.h> #include <qhash.h> #include <qobject.h> #include <qcoreapplication.h> @@ -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<QStandardPaths::StandardLocation>(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<QStandardPaths::StandardLocation>(type)); +} QT_END_NAMESPACE diff --git a/src/gui/util/qdesktopservices_mac.cpp b/src/gui/util/qdesktopservices_mac.cpp index d1711b0f15..f4b5263f62 100644 --- a/src/gui/util/qdesktopservices_mac.cpp +++ b/src/gui/util/qdesktopservices_mac.cpp @@ -45,7 +45,6 @@ #include <qstringlist.h> #include <qdir.h> #include <qurl.h> -#include <qstringlist.h> #include <private/qcore_mac_p.h> #include <qcoreapplication.h> @@ -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<UInt8 *>(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<QString>(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 374b06b4f0..c60cec8422 100644 --- a/src/gui/util/qdesktopservices_qpa.cpp +++ b/src/gui/util/qdesktopservices_qpa.cpp @@ -39,8 +39,7 @@ ** ****************************************************************************/ -#include <qcoreapplication.h> -#include <qdir.h> +#include <qdebug.h> #include <qurl.h> 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 41fc0f3b3c..f4d8fe99e1 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<LocalizerFunc> - (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 b06b52e399..8b120b4bf1 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 fa40113d43..cf8dce3734 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<QString, QString> 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 |