Warning, file /pim/trojita/src/Common/Paths.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com>
0002    Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
0003 
0004    This file is part of the Trojita Qt IMAP e-mail client,
0005    http://trojita.flaska.net/
0006 
0007    This program is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU General Public License as
0009    published by the Free Software Foundation; either version 2 of
0010    the License or (at your option) version 3 or any later version
0011    accepted by the membership of KDE e.V. (or its successor approved
0012    by the membership of KDE e.V.), which shall act as a proxy
0013    defined in Section 14 of version 3 of the license.
0014 
0015    This program is distributed in the hope that it will be useful,
0016    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018    GNU General Public License for more details.
0019 
0020    You should have received a copy of the GNU General Public License
0021    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022 */
0023 
0024 #include <QCoreApplication>
0025 #include <QDir>
0026 #include <QMap>
0027 #include <QStandardPaths>
0028 #include "Application.h"
0029 #include "Paths.h"
0030 
0031 namespace Common
0032 {
0033 
0034 QString writablePath(const LocationType location)
0035 {
0036     static QMap<LocationType, QString> map;
0037 
0038     if (map.isEmpty()) {
0039 
0040         const QString &origApplicationName = QCoreApplication::applicationName();
0041         const QString &origOrganizationDomain = QCoreApplication::organizationDomain();
0042         const QString &origOrganizationName = QCoreApplication::organizationName();
0043 
0044         QCoreApplication::setApplicationName(Common::Application::name);
0045         QCoreApplication::setOrganizationDomain(Common::Application::organization);
0046         QCoreApplication::setOrganizationName(Common::Application::organization);
0047 
0048         map[LOCATION_CACHE] = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
0049         map[LOCATION_DATA] = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
0050         map[LOCATION_DOWNLOAD] = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
0051 
0052         if (map[LOCATION_CACHE].isEmpty())
0053             map[LOCATION_CACHE] = QDir::homePath() + QLatin1String("/.cache");
0054 
0055         if (map[LOCATION_DATA].isEmpty())
0056             map[LOCATION_DATA] = QDir::homePath() + QLatin1String("/.data");
0057 
0058         if (map[LOCATION_DOWNLOAD].isEmpty())
0059             map[LOCATION_DOWNLOAD] = QDir::homePath();
0060 
0061 
0062         for (QMap<LocationType, QString>::iterator it = map.begin(); it != map.end(); ++it) {
0063             if (!it->endsWith(QLatin1Char('/')))
0064                 *it += QLatin1Char('/');
0065         }
0066 
0067         QString profileName = QString::fromUtf8(qgetenv("TROJITA_PROFILE"));
0068         if (!profileName.isEmpty())
0069             map[LOCATION_CACHE] += profileName + QLatin1Char('/');
0070 
0071         QCoreApplication::setApplicationName(origApplicationName);
0072         QCoreApplication::setOrganizationDomain(origOrganizationDomain);
0073         QCoreApplication::setOrganizationName(origOrganizationName);
0074 
0075     }
0076 
0077     return map[location];
0078 }
0079 
0080 }