From 84cf77bdf980b2e88938e94ace32865528dcc5fc Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Tue, 11 Nov 2014 16:34:13 +0100 Subject: Refactor path building from QStandardPath The duplicated logic was made apparent by the merge conflict resolution. Change-Id: Ib4558ca0b6b5084f851282916cbc9a6615ed33f9 Reviewed-by: Andras Becsi --- src/core/browser_context_adapter.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/core/browser_context_adapter.cpp') diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index b06515c2f..2b87e6e88 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -46,6 +46,17 @@ #include #include +namespace { +inline QString buildLocationFromStandardPath(const QString &standardPath) { + QString location = standardPath; + if (location.isEmpty()) + location = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName(); + + location.append(QDir::separator() % QLatin1String("QtWebEngine") + % QDir::separator() % QLatin1String("Default")); + return location; +} +} BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord) : m_offTheRecord(offTheRecord) @@ -80,22 +91,10 @@ BrowserContextAdapter* BrowserContextAdapter::offTheRecordContext() QString BrowserContextAdapter::dataPath() const { - QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation); - if (dataLocation.isEmpty()) - dataLocation = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName(); - - dataLocation.append(QDir::separator() % QLatin1String("QtWebEngine")); - dataLocation.append(QDir::separator() % QLatin1String("Default")); - return dataLocation; + return buildLocationFromStandardPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); } QString BrowserContextAdapter::cachePath() const { - QString cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); - if (cacheLocation.isEmpty()) - cacheLocation = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName(); - - cacheLocation.append(QDir::separator() % QLatin1String("QtWebEngine")); - cacheLocation.append(QDir::separator() % QLatin1String("Default")); - return cacheLocation; + return buildLocationFromStandardPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); } -- cgit v1.2.3