- Merged headless branch

This commit is contained in:
Christophe Dumez 2010-01-02 22:20:37 +00:00
commit cbe4bbac6a
16 changed files with 466 additions and 114 deletions

View file

@ -43,10 +43,24 @@
#include <QThread>
#include <ctime>
#include <QDateTime>
#include <QDesktopServices>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/conversion.hpp>
#ifdef DISABLE_GUI
#include <QCoreApplication>
#else
#include <QApplication>
#endif
#ifdef Q_WS_WIN
#include <shlobj.h>
#endif
#ifdef Q_WS_MAC
#include <Files.h>
#include <Folders.h>
#endif
#ifndef Q_WS_WIN
#ifdef Q_WS_MAC
#include <sys/param.h>
@ -168,8 +182,72 @@ public:
}
}
#ifdef Q_WS_MAC
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();
}
#endif
static QString QDesktopServicesDataLocation() {
#ifdef Q_WS_WIN
#if defined Q_WS_WINCE
if (SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE))
#else
if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE))
#endif
result = QString::fromWCharArray(path);
if (!QCoreApplication::applicationName().isEmpty())
result = result + QLatin1String("\\") + qApp->applicationName();
#else
#ifdef Q_WS_MAC
// http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html
FSRef ref;
OSErr err = FSFindFolder(kUserDomain, kApplicationSupportFolderType, false, &ref);
if (err)
return QString();
QString path = getFullPath(ref);
path += QLatin1Char('/') + qApp->applicationName();
return path;
#else
QString xdgDataHome = QLatin1String(qgetenv("XDG_DATA_HOME"));
if (xdgDataHome.isEmpty())
xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
xdgDataHome += QLatin1String("/data/")
+ qApp->applicationName();
return xdgDataHome;
#endif
#endif
}
static QString QDesktopServicesCacheLocation() {
#ifdef Q_WS_WIN
return QDesktopServicesDataLocation() + QLatin1String("\\cache");
#else
#ifdef Q_WS_MAC
// http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html
FSRef ref;
OSErr err = FSFindFolder(kUserDomain, kCachedDataFolderType, false, &ref);
if (err)
return QString();
QString path = getFullPath(ref);
path += QLatin1Char('/') + qApp->applicationName();
return path;
#else
QString xdgCacheHome = QLatin1String(qgetenv("XDG_CACHE_HOME"));
if (xdgCacheHome.isEmpty())
xdgCacheHome = QDir::homePath() + QLatin1String("/.cache");
xdgCacheHome += QLatin1Char('/') + QCoreApplication::applicationName();
return xdgCacheHome;
#endif
#endif
}
static QString searchEngineLocation() {
QString location = QDir::cleanPath(QDesktopServices::storageLocation(QDesktopServices::DataLocation)
QString location = QDir::cleanPath(QDesktopServicesDataLocation()
+ QDir::separator() + "search_engine");
QDir locationDir(location);
if(!locationDir.exists())
@ -178,7 +256,7 @@ public:
}
static QString BTBackupLocation() {
QString location = QDir::cleanPath(QDesktopServices::storageLocation(QDesktopServices::DataLocation)
QString location = QDir::cleanPath(QDesktopServicesDataLocation()
+ QDir::separator() + "BT_backup");
QDir locationDir(location);
if(!locationDir.exists())
@ -187,7 +265,7 @@ public:
}
static QString cacheLocation() {
QString location = QDir::cleanPath(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
QString location = QDir::cleanPath(QDesktopServicesCacheLocation());
QDir locationDir(location);
if(!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());